mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-05 21:53:15 +03:00
Parse XMP tag bytes without decoding to string
This commit is contained in:
parent
3c71559804
commit
27a8c3661d
|
@ -975,6 +975,11 @@ class TestImage:
|
|||
assert tag not in exif.get_ifd(0x8769)
|
||||
assert exif.get_ifd(0xA005)
|
||||
|
||||
def test_exif_from_xmp_bytes(self) -> None:
|
||||
im = Image.new("RGB", (1, 1))
|
||||
im.info["xmp"] = b'\xff tiff:Orientation="2"'
|
||||
assert im.getexif()[274] == 2
|
||||
|
||||
def test_empty_xmp(self) -> None:
|
||||
with Image.open("Tests/images/hopper.gif") as im:
|
||||
if ElementTree is None:
|
||||
|
|
|
@ -1538,10 +1538,11 @@ class Image:
|
|||
# XMP tags
|
||||
if ExifTags.Base.Orientation not in self._exif:
|
||||
xmp_tags = self.info.get("XML:com.adobe.xmp")
|
||||
pattern: str | bytes = r'tiff:Orientation(="|>)([0-9])'
|
||||
if not xmp_tags and (xmp_tags := self.info.get("xmp")):
|
||||
xmp_tags = xmp_tags.decode("utf-8")
|
||||
pattern = rb'tiff:Orientation(="|>)([0-9])'
|
||||
if xmp_tags:
|
||||
match = re.search(r'tiff:Orientation(="|>)([0-9])', xmp_tags)
|
||||
match = re.search(pattern, xmp_tags)
|
||||
if match:
|
||||
self._exif[ExifTags.Base.Orientation] = int(match[2])
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user