Skip to content

Commit

Permalink
Added getxmp() to WebPImagePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Nov 24, 2022
1 parent f276316 commit 66ec8e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Tests/test_file_webp_metadata.py
Expand Up @@ -11,6 +11,11 @@
skip_unless_feature("webp_mux"),
]

try:
from defusedxml import ElementTree
except ImportError:
ElementTree = None


def test_read_exif_metadata():

Expand Down Expand Up @@ -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>"
Expand Down
3 changes: 3 additions & 0 deletions src/PIL/WebPImagePlugin.py
Expand Up @@ -98,6 +98,9 @@ def _getexif(self):
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
Expand Down

0 comments on commit 66ec8e0

Please sign in to comment.