Skip to content

Commit cea8495

Browse files
committed
Corrected error when XMP is tuple
1 parent 5d52ede commit cea8495

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Tests/test_imageops.py

+9
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,15 @@ def check(orientation_im: Image.Image) -> None:
448448
assert 0x0112 not in transposed_im.getexif()
449449

450450

451+
def test_exif_transpose_with_xmp_tuple() -> None:
452+
with Image.open("Tests/images/xmp_tags_orientation.png") as im:
453+
assert im.getexif()[0x0112] == 3
454+
455+
im.info["xmp"] = (b"test",)
456+
transposed_im = ImageOps.exif_transpose(im)
457+
assert 0x0112 not in transposed_im.getexif()
458+
459+
451460
def test_exif_transpose_xml_without_xmp() -> None:
452461
with Image.open("Tests/images/xmp_tags_orientation.png") as im:
453462
assert im.getexif()[0x0112] == 3

src/PIL/ImageOps.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -729,11 +729,13 @@ def exif_transpose(image: Image.Image, *, in_place: bool = False) -> Image.Image
729729
r"<tiff:Orientation>([0-9])</tiff:Orientation>",
730730
):
731731
value = exif_image.info[key]
732-
exif_image.info[key] = (
733-
re.sub(pattern, "", value)
734-
if isinstance(value, str)
735-
else re.sub(pattern.encode(), b"", value)
736-
)
732+
if isinstance(value, str):
733+
value = re.sub(pattern, "", value)
734+
elif isinstance(value, tuple):
735+
value = tuple(re.sub(pattern.encode(), b"", v) for v in value)
736+
else:
737+
value = re.sub(pattern.encode(), b"", value)
738+
exif_image.info[key] = value
737739
if not in_place:
738740
return transposed_image
739741
elif not in_place:

0 commit comments

Comments
 (0)