Skip to content

Commit 41426a6

Browse files
authored
Merge pull request #8110 from radarhere/exififd
2 parents 5652113 + 5ce3f55 commit 41426a6

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Tests/test_file_libtiff.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,13 +685,18 @@ def test_save_ycbcr(self, tmp_path: Path) -> None:
685685
assert reloaded.tag_v2[530] == (1, 1)
686686
assert reloaded.tag_v2[532] == (0, 255, 128, 255, 128, 255)
687687

688-
def test_exif_ifd(self, tmp_path: Path) -> None:
689-
outfile = str(tmp_path / "temp.tif")
688+
def test_exif_ifd(self) -> None:
689+
out = io.BytesIO()
690690
with Image.open("Tests/images/tiff_adobe_deflate.tif") as im:
691691
assert im.tag_v2[34665] == 125456
692-
im.save(outfile)
692+
im.save(out, "TIFF")
693693

694-
with Image.open(outfile) as reloaded:
694+
with Image.open(out) as reloaded:
695+
assert 34665 not in reloaded.tag_v2
696+
697+
im.save(out, "TIFF", tiffinfo={34665: 125456})
698+
699+
with Image.open(out) as reloaded:
695700
if Image.core.libtiff_support_custom_tags:
696701
assert reloaded.tag_v2[34665] == 125456
697702

src/PIL/TiffImagePlugin.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,10 +1663,14 @@ def _save(im, fp, filename):
16631663
legacy_ifd = im.tag.to_v2()
16641664

16651665
supplied_tags = {**legacy_ifd, **getattr(im, "tag_v2", {})}
1666-
if SAMPLEFORMAT in supplied_tags:
1667-
# SAMPLEFORMAT is determined by the image format and should not be copied
1668-
# from legacy_ifd.
1669-
del supplied_tags[SAMPLEFORMAT]
1666+
for tag in (
1667+
# IFD offset that may not be correct in the saved image
1668+
EXIFIFD,
1669+
# Determined by the image format and should not be copied from legacy_ifd.
1670+
SAMPLEFORMAT,
1671+
):
1672+
if tag in supplied_tags:
1673+
del supplied_tags[tag]
16701674

16711675
# additions written by Greg Couch, [email protected]
16721676
# inspired by image-sig posting from Kevin Cazabon, [email protected]

0 commit comments

Comments
 (0)