Added getxmp() to WebPImagePlugin

This commit is contained in:
Andrew Murray 2022-11-25 08:47:40 +11:00
parent ad938d5421
commit 58cbcbf108
2 changed files with 24 additions and 0 deletions

View File

@ -11,6 +11,11 @@ pytestmark = [
skip_unless_feature("webp_mux"),
]
try:
from defusedxml import ElementTree
except ImportError:
ElementTree = None
def test_read_exif_metadata():
@ -110,6 +115,22 @@ def test_read_no_exif():
assert not webp_image._getexif()
def test_getxmp():
with Image.open("Tests/images/flower.webp") as im:
assert "xmp" not in im.info
assert im.getxmp() == {}
with Image.open("Tests/images/flower2.webp") as im:
if ElementTree is None:
with pytest.warns(UserWarning):
assert im.getxmp() == {}
else:
assert (
im.getxmp()["xmpmeta"]["xmptk"]
== "Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27 "
)
@skip_unless_feature("webp_anim")
def test_write_animated_metadata(tmp_path):
iccp_data = b"<iccp_data>"

View File

@ -98,6 +98,9 @@ class WebPImageFile(ImageFile.ImageFile):
return None
return self.getexif()._get_merged_dict()
def getxmp(self):
return self._getxmp(self.info["xmp"]) if "xmp" in self.info else {}
def seek(self, frame):
if not self._seek_check(frame):
return