From f26b47595b10eaf3d781a8ea3f357f78f0a2774c Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 19 Aug 2024 06:56:31 +1000 Subject: [PATCH] Get IPTC info from tag_v2 --- Tests/test_file_iptc.py | 10 ++++++++++ src/PIL/IptcImagePlugin.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_iptc.py b/Tests/test_file_iptc.py index b0ea2bf42..8a7c59fb1 100644 --- a/Tests/test_file_iptc.py +++ b/Tests/test_file_iptc.py @@ -77,6 +77,16 @@ def test_getiptcinfo_zero_padding() -> None: assert len(iptc) == 3 +def test_getiptcinfo_tiff() -> None: + # Arrange + with Image.open("Tests/images/hopper.Lab.tif") as im: + # Act + iptc = IptcImagePlugin.getiptcinfo(im) + + # Assert + assert iptc == {(1, 90): b"\x1b%G", (2, 0): b"\xcf\xc0"} + + def test_getiptcinfo_tiff_none() -> None: # Arrange with Image.open("Tests/images/hopper.tif") as im: diff --git a/src/PIL/IptcImagePlugin.py b/src/PIL/IptcImagePlugin.py index 17243e705..153243519 100644 --- a/src/PIL/IptcImagePlugin.py +++ b/src/PIL/IptcImagePlugin.py @@ -213,7 +213,7 @@ def getiptcinfo( # get raw data from the IPTC/NAA tag (PhotoShop tags the data # as 4-byte integers, so we cannot use the get method...) try: - data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK] + data = im.tag_v2[TiffImagePlugin.IPTC_NAA_CHUNK] except (AttributeError, KeyError): pass