diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 1485651c7..08f34b58e 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -255,6 +255,21 @@ class TestFileJpeg(PillowTestCase): # Should not raise a TypeError im._getexif() + def test_interop(self): + # Arrange + im = Image.open('Tests/images/flower.jpg') + + # Act + exif = im._getexif() + + # Assert + self.assertEqual(exif["interop"], { + 1: 'R98', + 2: b'0100', + 4097: 2272, + 4098: 1704 + }) + def test_progressive_compat(self): im1 = self.roundtrip(hopper()) self.assertFalse(im1.info.get("progressive")) diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index e43bdea6b..c2aaa7620 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -489,6 +489,18 @@ def _getexif(self): info = TiffImagePlugin.ImageFileDirectory_v1(head) info.load(file) exif[0x8825] = _fixup_dict(info) + # get interop + try: + # exif field 0xa005 is an offset pointer to the location + # of the nested embedded interop exif ifd. + # It should be a long, but may be corrupted. + file.seek(exif[0xa005]) + except (KeyError, TypeError): + pass + else: + info = TiffImagePlugin.ImageFileDirectory_v1(head) + info.load(file) + exif["interop"] = _fixup_dict(info) return exif