Skip to content

Commit

Permalink
Only preserve IPTC_NAA_CHUNK tag if type if BYTE or UNDEFINED
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Apr 4, 2024
1 parent e8ab564 commit 7cebf75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Tests/test_file_tiff.py
Expand Up @@ -621,6 +621,19 @@ def test_roundtrip_tiff_uint16(self, tmp_path: Path) -> None:

assert_image_equal_tofile(im, tmpfile)

def test_iptc(self, tmp_path: Path) -> None:
# Do not preserve IPTC_NAA_CHUNK by default if type is LONG
outfile = str(tmp_path / "temp.tif")
im = hopper()
ifd = TiffImagePlugin.ImageFileDirectory_v2()
ifd[33723] = 1
ifd.tagtype[33723] = 4
im.tag_v2 = ifd
im.save(outfile)

with Image.open(outfile) as im:
assert 33723 not in im.tag_v2

def test_rowsperstrip(self, tmp_path: Path) -> None:
outfile = str(tmp_path / "temp.tif")
im = hopper()
Expand Down
5 changes: 4 additions & 1 deletion src/PIL/TiffImagePlugin.py
Expand Up @@ -1665,7 +1665,10 @@ def _save(im, fp, filename):
PHOTOSHOP_CHUNK,
XMP,
):
if key in im.tag_v2:
if key in im.tag_v2 and not (
key == IPTC_NAA_CHUNK
and im.tag_v2.tagtype[key] not in (TiffTags.BYTE, TiffTags.UNDEFINED)
):
ifd[key] = im.tag_v2[key]
ifd.tagtype[key] = im.tag_v2.tagtype[key]

Expand Down

0 comments on commit 7cebf75

Please sign in to comment.