Skip to content

Commit

Permalink
Corrected error when XMP is tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Mar 3, 2025
1 parent 5d52ede commit cea8495
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Tests/test_imageops.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,15 @@ def check(orientation_im: Image.Image) -> None:
assert 0x0112 not in transposed_im.getexif()


def test_exif_transpose_with_xmp_tuple() -> None:
with Image.open("Tests/images/xmp_tags_orientation.png") as im:
assert im.getexif()[0x0112] == 3

im.info["xmp"] = (b"test",)
transposed_im = ImageOps.exif_transpose(im)
assert 0x0112 not in transposed_im.getexif()


def test_exif_transpose_xml_without_xmp() -> None:
with Image.open("Tests/images/xmp_tags_orientation.png") as im:
assert im.getexif()[0x0112] == 3
Expand Down
12 changes: 7 additions & 5 deletions src/PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,13 @@ def exif_transpose(image: Image.Image, *, in_place: bool = False) -> Image.Image
r"<tiff:Orientation>([0-9])</tiff:Orientation>",
):
value = exif_image.info[key]
exif_image.info[key] = (
re.sub(pattern, "", value)
if isinstance(value, str)
else re.sub(pattern.encode(), b"", value)
)
if isinstance(value, str):
value = re.sub(pattern, "", value)
elif isinstance(value, tuple):
value = tuple(re.sub(pattern.encode(), b"", v) for v in value)
else:
value = re.sub(pattern.encode(), b"", value)
exif_image.info[key] = value
if not in_place:
return transposed_image
elif not in_place:
Expand Down

0 comments on commit cea8495

Please sign in to comment.