Skip to content

Commit

Permalink
Test getexif() change
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Nov 12, 2024
1 parent e02eaa4 commit bf2c7a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Tests/test_file_avif.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ def test_exif(self) -> None:
exif = im.getexif()
assert exif[274] == 1

with Image.open("Tests/images/avif/xmp_tags_orientation.avif") as im:
exif = im.getexif()
assert exif[274] == 3

def test_exif_save_default(self, tmp_path: Path) -> None:
with Image.open("Tests/images/avif/exif.avif") as im:
test_file = str(tmp_path / "temp.avif")
Expand Down
9 changes: 5 additions & 4 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,11 +1548,12 @@ def getexif(self) -> Exif:

# XMP tags
if ExifTags.Base.Orientation not in self._exif:
xmp_tags = self.info.get("XML:com.adobe.xmp") or self.info.get("xmp")
if isinstance(xmp_tags, bytes):
xmp_tags = xmp_tags.decode("utf-8")
pattern = r'tiff:Orientation(="|>)([0-9])'
xmp_tags = self.info.get("XML:com.adobe.xmp")
if not xmp_tags and (xmp_tags := self.info.get("xmp")):
pattern = pattern.encode()
if xmp_tags:
match = re.search(r'tiff:Orientation(="|>)([0-9])', xmp_tags)
match = re.search(pattern, xmp_tags)
if match:
self._exif[ExifTags.Base.Orientation] = int(match[2])

Expand Down

0 comments on commit bf2c7a8

Please sign in to comment.