mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-07 13:25:24 +03:00
Handle IPTC TIFF tags with incorrect type (#8925)
This commit is contained in:
commit
2b39f7581e
|
@ -5,7 +5,7 @@ from io import BytesIO, StringIO
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import Image, IptcImagePlugin
|
from PIL import Image, IptcImagePlugin, TiffImagePlugin, TiffTags
|
||||||
|
|
||||||
from .helper import assert_image_equal, hopper
|
from .helper import assert_image_equal, hopper
|
||||||
|
|
||||||
|
@ -78,13 +78,19 @@ def test_getiptcinfo_zero_padding() -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_getiptcinfo_tiff() -> None:
|
def test_getiptcinfo_tiff() -> None:
|
||||||
# Arrange
|
expected = {(1, 90): b"\x1b%G", (2, 0): b"\xcf\xc0"}
|
||||||
|
|
||||||
with Image.open("Tests/images/hopper.Lab.tif") as im:
|
with Image.open("Tests/images/hopper.Lab.tif") as im:
|
||||||
# Act
|
|
||||||
iptc = IptcImagePlugin.getiptcinfo(im)
|
iptc = IptcImagePlugin.getiptcinfo(im)
|
||||||
|
|
||||||
# Assert
|
assert iptc == expected
|
||||||
assert iptc == {(1, 90): b"\x1b%G", (2, 0): b"\xcf\xc0"}
|
|
||||||
|
# Test with LONG tag type
|
||||||
|
with Image.open("Tests/images/hopper.Lab.tif") as im:
|
||||||
|
im.tag_v2.tagtype[TiffImagePlugin.IPTC_NAA_CHUNK] = TiffTags.LONG
|
||||||
|
iptc = IptcImagePlugin.getiptcinfo(im)
|
||||||
|
|
||||||
|
assert iptc == expected
|
||||||
|
|
||||||
|
|
||||||
def test_getiptcinfo_tiff_none() -> None:
|
def test_getiptcinfo_tiff_none() -> None:
|
||||||
|
|
|
@ -220,7 +220,7 @@ def getiptcinfo(
|
||||||
# get raw data from the IPTC/NAA tag (PhotoShop tags the data
|
# get raw data from the IPTC/NAA tag (PhotoShop tags the data
|
||||||
# as 4-byte integers, so we cannot use the get method...)
|
# as 4-byte integers, so we cannot use the get method...)
|
||||||
try:
|
try:
|
||||||
data = im.tag_v2[TiffImagePlugin.IPTC_NAA_CHUNK]
|
data = im.tag_v2._tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user