mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
commit
4ccdbf25cf
BIN
Tests/images/exif-ifd-offset.jpg
Normal file
BIN
Tests/images/exif-ifd-offset.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
Tests/images/sugarshack_ifd_offset.mpo
Normal file
BIN
Tests/images/sugarshack_ifd_offset.mpo
Normal file
Binary file not shown.
After Width: | Height: | Size: 117 KiB |
|
@ -581,6 +581,15 @@ class TestFileJpeg(PillowTestCase):
|
||||||
# OSError for unidentified image.
|
# OSError for unidentified image.
|
||||||
self.assertEqual(im.info.get("dpi"), (72, 72))
|
self.assertEqual(im.info.get("dpi"), (72, 72))
|
||||||
|
|
||||||
|
def test_ifd_offset_exif(self):
|
||||||
|
# Arrange
|
||||||
|
# This image has been manually hexedited to have an IFD offset of 10,
|
||||||
|
# in contrast to normal 8
|
||||||
|
im = Image.open("Tests/images/exif-ifd-offset.jpg")
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
self.assertEqual(im._getexif()[306], '2017:03:13 23:03:09')
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith('win32'), "Windows only")
|
@unittest.skipUnless(sys.platform.startswith('win32'), "Windows only")
|
||||||
class TestFileCloseW32(PillowTestCase):
|
class TestFileCloseW32(PillowTestCase):
|
||||||
|
|
|
@ -62,6 +62,14 @@ class TestFileMpo(PillowTestCase):
|
||||||
self.assertEqual(mpinfo[45056], b'0100')
|
self.assertEqual(mpinfo[45056], b'0100')
|
||||||
self.assertEqual(mpinfo[45057], 2)
|
self.assertEqual(mpinfo[45057], 2)
|
||||||
|
|
||||||
|
def test_mp_offset(self):
|
||||||
|
# This image has been manually hexedited to have an IFD offset of 10
|
||||||
|
# in APP2 data, in contrast to normal 8
|
||||||
|
im = Image.open("Tests/images/sugarshack_ifd_offset.mpo")
|
||||||
|
mpinfo = im._getmp()
|
||||||
|
self.assertEqual(mpinfo[45056], b'0100')
|
||||||
|
self.assertEqual(mpinfo[45057], 2)
|
||||||
|
|
||||||
def test_mp_attribute(self):
|
def test_mp_attribute(self):
|
||||||
for test_file in test_files:
|
for test_file in test_files:
|
||||||
im = Image.open(test_file)
|
im = Image.open(test_file)
|
||||||
|
|
|
@ -461,35 +461,36 @@ def _getexif(self):
|
||||||
data = self.info["exif"]
|
data = self.info["exif"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return None
|
||||||
file = io.BytesIO(data[6:])
|
fp = io.BytesIO(data[6:])
|
||||||
head = file.read(8)
|
head = fp.read(8)
|
||||||
# process dictionary
|
# process dictionary
|
||||||
info = TiffImagePlugin.ImageFileDirectory_v1(head)
|
info = TiffImagePlugin.ImageFileDirectory_v1(head)
|
||||||
info.load(file)
|
fp.seek(info.next)
|
||||||
|
info.load(fp)
|
||||||
exif = dict(_fixup_dict(info))
|
exif = dict(_fixup_dict(info))
|
||||||
# get exif extension
|
# get exif extension
|
||||||
try:
|
try:
|
||||||
# exif field 0x8769 is an offset pointer to the location
|
# exif field 0x8769 is an offset pointer to the location
|
||||||
# of the nested embedded exif ifd.
|
# of the nested embedded exif ifd.
|
||||||
# It should be a long, but may be corrupted.
|
# It should be a long, but may be corrupted.
|
||||||
file.seek(exif[0x8769])
|
fp.seek(exif[0x8769])
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
info = TiffImagePlugin.ImageFileDirectory_v1(head)
|
info = TiffImagePlugin.ImageFileDirectory_v1(head)
|
||||||
info.load(file)
|
info.load(fp)
|
||||||
exif.update(_fixup_dict(info))
|
exif.update(_fixup_dict(info))
|
||||||
# get gpsinfo extension
|
# get gpsinfo extension
|
||||||
try:
|
try:
|
||||||
# exif field 0x8825 is an offset pointer to the location
|
# exif field 0x8825 is an offset pointer to the location
|
||||||
# of the nested embedded gps exif ifd.
|
# of the nested embedded gps exif ifd.
|
||||||
# It should be a long, but may be corrupted.
|
# It should be a long, but may be corrupted.
|
||||||
file.seek(exif[0x8825])
|
fp.seek(exif[0x8825])
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
info = TiffImagePlugin.ImageFileDirectory_v1(head)
|
info = TiffImagePlugin.ImageFileDirectory_v1(head)
|
||||||
info.load(file)
|
info.load(fp)
|
||||||
exif[0x8825] = _fixup_dict(info)
|
exif[0x8825] = _fixup_dict(info)
|
||||||
|
|
||||||
return exif
|
return exif
|
||||||
|
@ -512,6 +513,7 @@ def _getmp(self):
|
||||||
# process dictionary
|
# process dictionary
|
||||||
try:
|
try:
|
||||||
info = TiffImagePlugin.ImageFileDirectory_v2(head)
|
info = TiffImagePlugin.ImageFileDirectory_v2(head)
|
||||||
|
file_contents.seek(info.next)
|
||||||
info.load(file_contents)
|
info.load(file_contents)
|
||||||
mp = dict(info)
|
mp = dict(info)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user