fixing xmp tag orientation generated by exiftool

This commit is contained in:
Alexander Piskun 2022-07-26 00:30:32 +03:00
parent ce7af49eed
commit 6e97da0260
No known key found for this signature in database
GPG Key ID: 1F0BF0EC3CF22721
4 changed files with 18 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -351,6 +351,13 @@ def test_exif_transpose():
transposed_im = ImageOps.exif_transpose(im)
assert 0x0112 not in transposed_im.getexif()
# Orientation from "XML:com.adobe.xmp" info key (from exiftool)
with Image.open("Tests/images/xmp_orientation_exiftool.png") as im:
assert im.getexif()[0x0112] == 8
transposed_im = ImageOps.exif_transpose(im)
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
# to have a different orientation

View File

@ -1407,6 +1407,12 @@ class Image:
match = re.search(r'tiff:Orientation="([0-9])"', xmp_tags)
if match:
self._exif[0x0112] = int(match[1])
else:
match = re.search(
r"<tiff:Orientation>([0-9])</tiff:Orientation>", xmp_tags
)
if match:
self._exif[0x0112] = int(match[1])
return self._exif

View File

@ -606,5 +606,10 @@ def exif_transpose(image):
"",
transposed_image.info["XML:com.adobe.xmp"],
)
transposed_image.info["XML:com.adobe.xmp"] = re.sub(
r"<tiff:Orientation>([0-9])</tiff:Orientation>",
"",
transposed_image.info["XML:com.adobe.xmp"],
)
return transposed_image
return image.copy()