mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 01:04:29 +03:00
Merge pull request #5144 from UrielMaD/feature_xmp
This commit is contained in:
commit
6812205f18
BIN
Tests/images/xmp_test.jpg
Normal file
BIN
Tests/images/xmp_test.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 MiB |
9
Tests/test_image_getxmp.py
Normal file
9
Tests/test_image_getxmp.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
def test_getxmp():
|
||||||
|
with Image.open("Tests/images/xmp_test.jpg") as im:
|
||||||
|
xmp = im.getxmp()
|
||||||
|
|
||||||
|
assert isinstance(xmp, dict)
|
||||||
|
assert xmp["Description"]["Version"] == "10.4"
|
|
@ -528,6 +528,7 @@ class Image:
|
||||||
self.readonly = 0
|
self.readonly = 0
|
||||||
self.pyaccess = None
|
self.pyaccess = None
|
||||||
self._exif = None
|
self._exif = None
|
||||||
|
self._xmp = None
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name == "category":
|
if name == "category":
|
||||||
|
@ -1339,6 +1340,27 @@ class Image:
|
||||||
|
|
||||||
return self._exif
|
return self._exif
|
||||||
|
|
||||||
|
def getxmp(self):
|
||||||
|
"""
|
||||||
|
Returns a dictionary containing the xmp tags for a given image.
|
||||||
|
:returns: XMP tags in a dictionary.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self._xmp is None:
|
||||||
|
self._xmp = {}
|
||||||
|
|
||||||
|
for segment, content in self.applist:
|
||||||
|
if segment == "APP1":
|
||||||
|
marker, xmp_tags = content.rsplit(b"\x00", 1)
|
||||||
|
if marker == b"http://ns.adobe.com/xap/1.0/":
|
||||||
|
root = xml.etree.ElementTree.fromstring(xmp_tags)
|
||||||
|
for element in root.findall(".//"):
|
||||||
|
self._xmp[element.tag.split("}")[1]] = {
|
||||||
|
child.split("}")[1]: value
|
||||||
|
for child, value in element.attrib.items()
|
||||||
|
}
|
||||||
|
return self._xmp
|
||||||
|
|
||||||
def getim(self):
|
def getim(self):
|
||||||
"""
|
"""
|
||||||
Returns a capsule that points to the internal image memory.
|
Returns a capsule that points to the internal image memory.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user