mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-04 20:03:20 +03:00
Handle UNDEFINED XMP data
This commit is contained in:
parent
1bf32ae892
commit
cb077a16c8
|
@ -14,6 +14,7 @@ from PIL import (
|
||||||
ImageFile,
|
ImageFile,
|
||||||
JpegImagePlugin,
|
JpegImagePlugin,
|
||||||
TiffImagePlugin,
|
TiffImagePlugin,
|
||||||
|
TiffTags,
|
||||||
UnidentifiedImageError,
|
UnidentifiedImageError,
|
||||||
)
|
)
|
||||||
from PIL.TiffImagePlugin import RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION
|
from PIL.TiffImagePlugin import RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION
|
||||||
|
@ -900,6 +901,29 @@ class TestFileTiff:
|
||||||
assert description[0]["format"] == "image/tiff"
|
assert description[0]["format"] == "image/tiff"
|
||||||
assert description[3]["BitsPerSample"]["Seq"]["li"] == ["8", "8", "8"]
|
assert description[3]["BitsPerSample"]["Seq"]["li"] == ["8", "8", "8"]
|
||||||
|
|
||||||
|
def test_getxmp_undefined(self, tmp_path: Path) -> None:
|
||||||
|
tmpfile = tmp_path / "temp.tif"
|
||||||
|
im = Image.new("L", (1, 1))
|
||||||
|
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
||||||
|
ifd.tagtype[700] = TiffTags.UNDEFINED
|
||||||
|
with Image.open("Tests/images/lab.tif") as im_xmp:
|
||||||
|
ifd[700] = im_xmp.info["xmp"]
|
||||||
|
im.save(tmpfile, tiffinfo=ifd)
|
||||||
|
|
||||||
|
with Image.open(tmpfile) as im_reloaded:
|
||||||
|
if ElementTree is None:
|
||||||
|
with pytest.warns(
|
||||||
|
UserWarning,
|
||||||
|
match="XMP data cannot be read without defusedxml dependency",
|
||||||
|
):
|
||||||
|
assert im_reloaded.getxmp() == {}
|
||||||
|
else:
|
||||||
|
assert "xmp" in im_reloaded.info
|
||||||
|
xmp = im_reloaded.getxmp()
|
||||||
|
|
||||||
|
description = xmp["xmpmeta"]["RDF"]["Description"]
|
||||||
|
assert description[0]["format"] == "image/tiff"
|
||||||
|
|
||||||
def test_get_photoshop_blocks(self) -> None:
|
def test_get_photoshop_blocks(self) -> None:
|
||||||
with Image.open("Tests/images/lab.tif") as im:
|
with Image.open("Tests/images/lab.tif") as im:
|
||||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||||
|
|
|
@ -1259,7 +1259,10 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self.fp.seek(self._frame_pos[frame])
|
self.fp.seek(self._frame_pos[frame])
|
||||||
self.tag_v2.load(self.fp)
|
self.tag_v2.load(self.fp)
|
||||||
if XMP in self.tag_v2:
|
if XMP in self.tag_v2:
|
||||||
self.info["xmp"] = self.tag_v2[XMP]
|
xmp = self.tag_v2[XMP]
|
||||||
|
if isinstance(xmp, tuple) and len(xmp) == 1:
|
||||||
|
xmp = xmp[0]
|
||||||
|
self.info["xmp"] = xmp
|
||||||
elif "xmp" in self.info:
|
elif "xmp" in self.info:
|
||||||
del self.info["xmp"]
|
del self.info["xmp"]
|
||||||
self._reload_exif()
|
self._reload_exif()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user