Skip to content

Commit

Permalink
Save base IFDs when converting Exif to bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Feb 21, 2021
1 parent faf8fad commit 4b14f01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Tests/test_image.py
Expand Up @@ -752,6 +752,14 @@ def test_exif_interop(self):
4098: 1704,
}

def test_exif_ifd(self):
im = Image.open("Tests/images/flower.jpg")
exif = im.getexif()

reloaded_exif = Image.Exif()
reloaded_exif.load(exif.tobytes())
assert reloaded_exif.get_ifd(0x8769) == exif.get_ifd(0x8769)

@pytest.mark.parametrize(
"test_module",
[PIL, Image],
Expand Down
2 changes: 2 additions & 0 deletions src/PIL/Image.py
Expand Up @@ -3371,6 +3371,8 @@ def tobytes(self, offset=8):
head = b"MM\x00\x2A\x00\x00\x00\x08"
ifd = TiffImagePlugin.ImageFileDirectory_v2(ifh=head)
for tag, value in self.items():
if tag in [0x8769, 0x8225] and not isinstance(value, dict):
value = self.get_ifd(tag)
ifd[tag] = value
return b"Exif\x00\x00" + head + ifd.tobytes(offset)

Expand Down

0 comments on commit 4b14f01

Please sign in to comment.