mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Merge pull request #6463 from bigcat88/xmp-tags-orientation
Parse orientation from XMP tag contents
This commit is contained in:
commit
363586be6a
BIN
Tests/images/xmp_tags_orientation_exiftool.png
Normal file
BIN
Tests/images/xmp_tags_orientation_exiftool.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
|
@ -345,11 +345,15 @@ def test_exif_transpose():
|
|||
check(orientation_im)
|
||||
|
||||
# Orientation from "XML:com.adobe.xmp" info key
|
||||
with Image.open("Tests/images/xmp_tags_orientation.png") as im:
|
||||
assert im.getexif()[0x0112] == 3
|
||||
for suffix in ("", "_exiftool"):
|
||||
with Image.open("Tests/images/xmp_tags_orientation" + suffix + ".png") as im:
|
||||
assert im.getexif()[0x0112] == 3
|
||||
|
||||
transposed_im = ImageOps.exif_transpose(im)
|
||||
assert 0x0112 not in transposed_im.getexif()
|
||||
transposed_im = ImageOps.exif_transpose(im)
|
||||
assert 0x0112 not in transposed_im.getexif()
|
||||
|
||||
transposed_im._reload_exif()
|
||||
assert 0x0112 not in transposed_im.getexif()
|
||||
|
||||
# Orientation from "Raw profile type exif" info key
|
||||
# This test image has been manually hexedited from exif_imagemagick.png
|
||||
|
|
|
@ -1404,9 +1404,9 @@ class Image:
|
|||
if 0x0112 not in self._exif:
|
||||
xmp_tags = self.info.get("XML:com.adobe.xmp")
|
||||
if xmp_tags:
|
||||
match = re.search(r'tiff:Orientation="([0-9])"', xmp_tags)
|
||||
match = re.search(r'tiff:Orientation(="|>)([0-9])', xmp_tags)
|
||||
if match:
|
||||
self._exif[0x0112] = int(match[1])
|
||||
self._exif[0x0112] = int(match[2])
|
||||
|
||||
return self._exif
|
||||
|
||||
|
|
|
@ -601,10 +601,12 @@ def exif_transpose(image):
|
|||
"Raw profile type exif"
|
||||
] = transposed_exif.tobytes().hex()
|
||||
elif "XML:com.adobe.xmp" in transposed_image.info:
|
||||
transposed_image.info["XML:com.adobe.xmp"] = re.sub(
|
||||
for pattern in (
|
||||
r'tiff:Orientation="([0-9])"',
|
||||
"",
|
||||
transposed_image.info["XML:com.adobe.xmp"],
|
||||
)
|
||||
r"<tiff:Orientation>([0-9])</tiff:Orientation>",
|
||||
):
|
||||
transposed_image.info["XML:com.adobe.xmp"] = re.sub(
|
||||
pattern, "", transposed_image.info["XML:com.adobe.xmp"]
|
||||
)
|
||||
return transposed_image
|
||||
return image.copy()
|
||||
|
|
Loading…
Reference in New Issue
Block a user