Skip to content

Commit

Permalink
fixing xmp tag orientation generated by exiftool
Browse files Browse the repository at this point in the history
  • Loading branch information
bigcat88 committed Jul 25, 2022
1 parent ce7af49 commit 6e97da0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Binary file added Tests/images/xmp_orientation_exifool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Tests/test_imageops.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ def check(orientation_im):
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
Expand Down
6 changes: 6 additions & 0 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,12 @@ def getexif(self):
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

Expand Down
5 changes: 5 additions & 0 deletions src/PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 6e97da0

Please sign in to comment.