|
14 | 14 | ImageFile, |
15 | 15 | JpegImagePlugin, |
16 | 16 | TiffImagePlugin, |
| 17 | + TiffTags, |
17 | 18 | UnidentifiedImageError, |
18 | 19 | ) |
19 | 20 | from PIL.TiffImagePlugin import RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION |
@@ -900,6 +901,29 @@ def test_getxmp(self) -> None: |
900 | 901 | assert description[0]["format"] == "image/tiff" |
901 | 902 | assert description[3]["BitsPerSample"]["Seq"]["li"] == ["8", "8", "8"] |
902 | 903 |
|
| 904 | + def test_getxmp_undefined(self, tmp_path: Path) -> None: |
| 905 | + tmpfile = tmp_path / "temp.tif" |
| 906 | + im = Image.new("L", (1, 1)) |
| 907 | + ifd = TiffImagePlugin.ImageFileDirectory_v2() |
| 908 | + ifd.tagtype[700] = TiffTags.UNDEFINED |
| 909 | + with Image.open("Tests/images/lab.tif") as im_xmp: |
| 910 | + ifd[700] = im_xmp.info["xmp"] |
| 911 | + im.save(tmpfile, tiffinfo=ifd) |
| 912 | + |
| 913 | + with Image.open(tmpfile) as im_reloaded: |
| 914 | + if ElementTree is None: |
| 915 | + with pytest.warns( |
| 916 | + UserWarning, |
| 917 | + match="XMP data cannot be read without defusedxml dependency", |
| 918 | + ): |
| 919 | + assert im_reloaded.getxmp() == {} |
| 920 | + else: |
| 921 | + assert "xmp" in im_reloaded.info |
| 922 | + xmp = im_reloaded.getxmp() |
| 923 | + |
| 924 | + description = xmp["xmpmeta"]["RDF"]["Description"] |
| 925 | + assert description[0]["format"] == "image/tiff" |
| 926 | + |
903 | 927 | def test_get_photoshop_blocks(self) -> None: |
904 | 928 | with Image.open("Tests/images/lab.tif") as im: |
905 | 929 | assert isinstance(im, TiffImagePlugin.TiffImageFile) |
|
0 commit comments