mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Merge pull request #6758 from radarhere/webp_getxmp
Resolves https://github.com/python-pillow/Pillow/issues/6757
This commit is contained in:
commit
066c3ab73b
|
@ -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>"
|
||||
|
|
|
@ -45,6 +45,12 @@ removes the hidden RGB values for better compression by default in libwebp 0.5
|
|||
or later. By setting this option to ``True``, the encoder will keep the hidden
|
||||
RGB values.
|
||||
|
||||
getxmp()
|
||||
^^^^^^^^
|
||||
|
||||
`XMP data <https://en.wikipedia.org/wiki/Extensible_Metadata_Platform>`_ can now be
|
||||
decoded for WEBP images through ``getxmp()``.
|
||||
|
||||
Security
|
||||
========
|
||||
|
||||
|
|
|
@ -98,6 +98,15 @@ class WebPImageFile(ImageFile.ImageFile):
|
|||
return None
|
||||
return self.getexif()._get_merged_dict()
|
||||
|
||||
def getxmp(self):
|
||||
"""
|
||||
Returns a dictionary containing the XMP tags.
|
||||
Requires defusedxml to be installed.
|
||||
|
||||
:returns: XMP tags in a dictionary.
|
||||
"""
|
||||
return self._getxmp(self.info["xmp"]) if "xmp" in self.info else {}
|
||||
|
||||
def seek(self, frame):
|
||||
if not self._seek_check(frame):
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user