Skip to content

Commit

Permalink
Keep new IFDs when converting EXIF to bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 28, 2024
1 parent 1a79d10 commit 9368a86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,10 @@ def test_empty_get_ifd(self) -> None:
ifd[36864] = b"0220"
assert exif.get_ifd(0x8769) == {36864: b"0220"}

reloaded_exif = Image.Exif()
reloaded_exif.load(exif.tobytes())
assert reloaded_exif.get_ifd(0x8769) == {36864: b"0220"}

@mark_if_feature_version(
pytest.mark.valgrind_known_error, "libjpeg_turbo", "2.0", reason="Known Failing"
)
Expand Down
3 changes: 3 additions & 0 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4023,6 +4023,9 @@ def tobytes(self, offset: int = 8) -> bytes:

head = self._get_head()
ifd = TiffImagePlugin.ImageFileDirectory_v2(ifh=head)
for tag, ifd_dict in self._ifds.items():
if tag not in self:
ifd[tag] = ifd_dict
for tag, value in self.items():
if tag in [
ExifTags.IFD.Exif,
Expand Down

0 comments on commit 9368a86

Please sign in to comment.