Skip to content

Commit 363586b

Browse files
authored
Merge pull request #6463 from bigcat88/xmp-tags-orientation
Parse orientation from XMP tag contents
2 parents 4dcb149 + 5d8dacf commit 363586b

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed
1.23 KB
Loading

Tests/test_imageops.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,15 @@ def check(orientation_im):
345345
check(orientation_im)
346346

347347
# Orientation from "XML:com.adobe.xmp" info key
348-
with Image.open("Tests/images/xmp_tags_orientation.png") as im:
349-
assert im.getexif()[0x0112] == 3
348+
for suffix in ("", "_exiftool"):
349+
with Image.open("Tests/images/xmp_tags_orientation" + suffix + ".png") as im:
350+
assert im.getexif()[0x0112] == 3
350351

351-
transposed_im = ImageOps.exif_transpose(im)
352-
assert 0x0112 not in transposed_im.getexif()
352+
transposed_im = ImageOps.exif_transpose(im)
353+
assert 0x0112 not in transposed_im.getexif()
354+
355+
transposed_im._reload_exif()
356+
assert 0x0112 not in transposed_im.getexif()
353357

354358
# Orientation from "Raw profile type exif" info key
355359
# This test image has been manually hexedited from exif_imagemagick.png

src/PIL/Image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,9 +1404,9 @@ def getexif(self):
14041404
if 0x0112 not in self._exif:
14051405
xmp_tags = self.info.get("XML:com.adobe.xmp")
14061406
if xmp_tags:
1407-
match = re.search(r'tiff:Orientation="([0-9])"', xmp_tags)
1407+
match = re.search(r'tiff:Orientation(="|>)([0-9])', xmp_tags)
14081408
if match:
1409-
self._exif[0x0112] = int(match[1])
1409+
self._exif[0x0112] = int(match[2])
14101410

14111411
return self._exif
14121412

src/PIL/ImageOps.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,12 @@ def exif_transpose(image):
601601
"Raw profile type exif"
602602
] = transposed_exif.tobytes().hex()
603603
elif "XML:com.adobe.xmp" in transposed_image.info:
604-
transposed_image.info["XML:com.adobe.xmp"] = re.sub(
604+
for pattern in (
605605
r'tiff:Orientation="([0-9])"',
606-
"",
607-
transposed_image.info["XML:com.adobe.xmp"],
608-
)
606+
r"<tiff:Orientation>([0-9])</tiff:Orientation>",
607+
):
608+
transposed_image.info["XML:com.adobe.xmp"] = re.sub(
609+
pattern, "", transposed_image.info["XML:com.adobe.xmp"]
610+
)
609611
return transposed_image
610612
return image.copy()

0 commit comments

Comments
 (0)