Skip to content

Commit

Permalink
Merge pull request #1 from radarhere/xmp-tags-orientation
Browse files Browse the repository at this point in the history
Simplified code
  • Loading branch information
bigcat88 authored Jul 26, 2022
2 parents db20d0f + f42e255 commit cce09b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
10 changes: 2 additions & 8 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1404,15 +1404,9 @@ def getexif(self):
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])
else:
match = re.search(
r"<tiff:Orientation>([0-9])</tiff:Orientation>", xmp_tags
)
if match:
self._exif[0x0112] = int(match[1])
self._exif[0x0112] = int(match[2])

return self._exif

Expand Down
13 changes: 5 additions & 8 deletions src/PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,15 +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"],
)
transposed_image.info["XML:com.adobe.xmp"] = re.sub(
r"<tiff:Orientation>([0-9])</tiff:Orientation>",
"",
transposed_image.info["XML:com.adobe.xmp"],
)
):
transposed_image.info["XML:com.adobe.xmp"] = re.sub(
pattern, "", transposed_image.info["XML:com.adobe.xmp"]
)
return transposed_image
return image.copy()

0 comments on commit cce09b7

Please sign in to comment.