From e763f8f2be026cd598f0e1bd3c8b50c5b2d9be64 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 22 Feb 2021 07:47:59 +1100 Subject: [PATCH] Save interop IFD when converting Exif to bytes --- Tests/test_image.py | 9 +++++++-- src/PIL/Image.py | 7 +++++++ src/PIL/TiffTags.py | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index b1db41235..e1c14d0d8 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -752,9 +752,14 @@ class TestImage: 4098: 1704, } + reloaded_exif = Image.Exif() + reloaded_exif.load(exif.tobytes()) + assert reloaded_exif.get_ifd(0xA005) == exif.get_ifd(0xA005) + def test_exif_ifd(self): - im = Image.open("Tests/images/flower.jpg") - exif = im.getexif() + with Image.open("Tests/images/flower.jpg") as im: + exif = im.getexif() + del exif.get_ifd(0x8769)[0xA005] reloaded_exif = Image.Exif() reloaded_exif.load(exif.tobytes()) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index d318bc236..df3ebfd18 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -3373,6 +3373,13 @@ class Exif(MutableMapping): for tag, value in self.items(): if tag in [0x8769, 0x8225] and not isinstance(value, dict): value = self.get_ifd(tag) + if ( + tag == 0x8769 + and 0xA005 in value + and not isinstance(value[0xA005], dict) + ): + value = value.copy() + value[0xA005] = self.get_ifd(0xA005) ifd[tag] = value return b"Exif\x00\x00" + head + ifd.tobytes(offset) diff --git a/src/PIL/TiffTags.py b/src/PIL/TiffTags.py index 796ff3479..9e9e117a4 100644 --- a/src/PIL/TiffTags.py +++ b/src/PIL/TiffTags.py @@ -184,6 +184,7 @@ TAGS_V2 = { 34665: ("ExifIFD", LONG, 1), 34675: ("ICCProfile", UNDEFINED, 1), 34853: ("GPSInfoIFD", LONG, 1), + 40965: ("InteroperabilityIFD", LONG, 1), # MPInfo 45056: ("MPFVersion", UNDEFINED, 1), 45057: ("NumberOfImages", LONG, 1),