Skip to content

Commit 6e97da0

Browse files
committed
fixing xmp tag orientation generated by exiftool
1 parent ce7af49 commit 6e97da0

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed
1.89 KB
Loading

Tests/test_imageops.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ def check(orientation_im):
351351
transposed_im = ImageOps.exif_transpose(im)
352352
assert 0x0112 not in transposed_im.getexif()
353353

354+
# Orientation from "XML:com.adobe.xmp" info key (from exiftool)
355+
with Image.open("Tests/images/xmp_orientation_exiftool.png") as im:
356+
assert im.getexif()[0x0112] == 8
357+
358+
transposed_im = ImageOps.exif_transpose(im)
359+
assert 0x0112 not in transposed_im.getexif()
360+
354361
# Orientation from "Raw profile type exif" info key
355362
# This test image has been manually hexedited from exif_imagemagick.png
356363
# to have a different orientation

src/PIL/Image.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,12 @@ def getexif(self):
14071407
match = re.search(r'tiff:Orientation="([0-9])"', xmp_tags)
14081408
if match:
14091409
self._exif[0x0112] = int(match[1])
1410+
else:
1411+
match = re.search(
1412+
r"<tiff:Orientation>([0-9])</tiff:Orientation>", xmp_tags
1413+
)
1414+
if match:
1415+
self._exif[0x0112] = int(match[1])
14101416

14111417
return self._exif
14121418

src/PIL/ImageOps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,5 +606,10 @@ def exif_transpose(image):
606606
"",
607607
transposed_image.info["XML:com.adobe.xmp"],
608608
)
609+
transposed_image.info["XML:com.adobe.xmp"] = re.sub(
610+
r"<tiff:Orientation>([0-9])</tiff:Orientation>",
611+
"",
612+
transposed_image.info["XML:com.adobe.xmp"],
613+
)
609614
return transposed_image
610615
return image.copy()

0 commit comments

Comments
 (0)