mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Moved getxmp() into JpegImageFile
This commit is contained in:
parent
43c41720e9
commit
2c8684c525
|
@ -805,6 +805,13 @@ class TestFileJpeg:
|
||||||
# Assert the entire file has not been read
|
# Assert the entire file has not been read
|
||||||
assert 0 < buffer.max_pos < size
|
assert 0 < buffer.max_pos < size
|
||||||
|
|
||||||
|
def test_getxmp(self):
|
||||||
|
with Image.open("Tests/images/xmp_test.jpg") as im:
|
||||||
|
xmp = im.getxmp()
|
||||||
|
|
||||||
|
assert isinstance(xmp, dict)
|
||||||
|
assert xmp["Description"]["Version"] == "10.4"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not is_win32(), reason="Windows only")
|
@pytest.mark.skipif(not is_win32(), reason="Windows only")
|
||||||
@skip_unless_feature("jpg")
|
@skip_unless_feature("jpg")
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
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,7 +528,6 @@ 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":
|
||||||
|
@ -1340,27 +1339,6 @@ 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.
|
||||||
|
|
|
@ -39,6 +39,7 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import warnings
|
import warnings
|
||||||
|
import xml.etree.ElementTree
|
||||||
|
|
||||||
from . import Image, ImageFile, TiffImagePlugin
|
from . import Image, ImageFile, TiffImagePlugin
|
||||||
from ._binary import i16be as i16
|
from ._binary import i16be as i16
|
||||||
|
@ -358,6 +359,7 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
self.app = {} # compatibility
|
self.app = {} # compatibility
|
||||||
self.applist = []
|
self.applist = []
|
||||||
self.icclist = []
|
self.icclist = []
|
||||||
|
self._xmp = None
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
@ -474,6 +476,27 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
def _getmp(self):
|
def _getmp(self):
|
||||||
return _getmp(self)
|
return _getmp(self)
|
||||||
|
|
||||||
|
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 _getexif(self):
|
def _getexif(self):
|
||||||
if "exif" not in self.info:
|
if "exif" not in self.info:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user