Skip to content

Commit 7cebf75

Browse files
committed
Only preserve IPTC_NAA_CHUNK tag if type if BYTE or UNDEFINED
1 parent e8ab564 commit 7cebf75

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Tests/test_file_tiff.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,19 @@ def test_roundtrip_tiff_uint16(self, tmp_path: Path) -> None:
621621

622622
assert_image_equal_tofile(im, tmpfile)
623623

624+
def test_iptc(self, tmp_path: Path) -> None:
625+
# Do not preserve IPTC_NAA_CHUNK by default if type is LONG
626+
outfile = str(tmp_path / "temp.tif")
627+
im = hopper()
628+
ifd = TiffImagePlugin.ImageFileDirectory_v2()
629+
ifd[33723] = 1
630+
ifd.tagtype[33723] = 4
631+
im.tag_v2 = ifd
632+
im.save(outfile)
633+
634+
with Image.open(outfile) as im:
635+
assert 33723 not in im.tag_v2
636+
624637
def test_rowsperstrip(self, tmp_path: Path) -> None:
625638
outfile = str(tmp_path / "temp.tif")
626639
im = hopper()

src/PIL/TiffImagePlugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,10 @@ def _save(im, fp, filename):
16651665
PHOTOSHOP_CHUNK,
16661666
XMP,
16671667
):
1668-
if key in im.tag_v2:
1668+
if key in im.tag_v2 and not (
1669+
key == IPTC_NAA_CHUNK
1670+
and im.tag_v2.tagtype[key] not in (TiffTags.BYTE, TiffTags.UNDEFINED)
1671+
):
16691672
ifd[key] = im.tag_v2[key]
16701673
ifd.tagtype[key] = im.tag_v2.tagtype[key]
16711674

0 commit comments

Comments
 (0)