@@ -709,17 +709,18 @@ def exif_transpose(image: Image.Image, *, in_place: bool = False) -> Image.Image
709
709
exif_image .info ["exif" ] = exif .tobytes ()
710
710
elif "Raw profile type exif" in exif_image .info :
711
711
exif_image .info ["Raw profile type exif" ] = exif .tobytes ().hex ()
712
- elif "XML:com.adobe.xmp" in exif_image .info :
713
- for pattern in (
714
- r'tiff:Orientation="([0-9])"' ,
715
- r"<tiff:Orientation>([0-9])</tiff:Orientation>" ,
716
- ):
717
- exif_image .info ["XML:com.adobe.xmp" ] = re .sub (
718
- pattern , "" , exif_image .info ["XML:com.adobe.xmp" ]
719
- )
720
- exif_image .info ["xmp" ] = re .sub (
721
- pattern .encode (), b"" , exif_image .info ["xmp" ]
722
- )
712
+ for key in ("XML:com.adobe.xmp" , "xmp" ):
713
+ if key in exif_image .info :
714
+ for pattern in (
715
+ r'tiff:Orientation="([0-9])"' ,
716
+ r"<tiff:Orientation>([0-9])</tiff:Orientation>" ,
717
+ ):
718
+ value = exif_image .info [key ]
719
+ exif_image .info [key ] = (
720
+ re .sub (pattern , "" , value )
721
+ if isinstance (value , str )
722
+ else re .sub (pattern .encode (), b"" , value )
723
+ )
723
724
if not in_place :
724
725
return transposed_image
725
726
elif not in_place :
0 commit comments