Skip to content

Commit

Permalink
Do not preserve EXIFIFD tag by default
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jun 6, 2024
1 parent 2d06108 commit 826a4ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 8 additions & 3 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,17 @@ def test_save_ycbcr(self, tmp_path: Path) -> None:
assert reloaded.tag_v2[532] == (0, 255, 128, 255, 128, 255)

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

with Image.open(outfile) as reloaded:
with Image.open(out) as reloaded:
assert 34665 not in reloaded.tag_v2

im.save(out, "TIFF", tiffinfo={34665: 125456})

with Image.open(out) as reloaded:
if Image.core.libtiff_support_custom_tags:
assert reloaded.tag_v2[34665] == 125456

Expand Down
5 changes: 3 additions & 2 deletions src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1819,8 +1819,9 @@ def _save(im, fp, filename):
# SAMPLEFORMAT is determined by the image format and should not be copied
# from legacy_ifd.
supplied_tags = {**getattr(im, "tag_v2", {}), **legacy_ifd}
if SAMPLEFORMAT in supplied_tags:
del supplied_tags[SAMPLEFORMAT]
for tag in (EXIFIFD, SAMPLEFORMAT):
if tag in supplied_tags:
del supplied_tags[tag]

for tag, value in itertools.chain(ifd.items(), supplied_tags.items()):
# Libtiff can only process certain core items without adding
Expand Down

0 comments on commit 826a4ae

Please sign in to comment.