You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromPILimportImage, ImageOpsimg=Image.new('L', (200, 200))
# Setting the orientation to rotate 270° clockwiseimg.getexif()[0x0112] =6# this will cause a KeyErrortransposed=ImageOps.exif_transpose(img)
Possible fix
From some quick reading, I believe this line is the issue. The EXIF tags in a newly transposed image are empty:
But the method attempts to remove the orientation tag from this empty dictionary. It seems the change was made to avoid editing the EXIF tags of the original image (#5546), and using copy.copy would probably fix this:
fromcopyimportcopytransposed_exif=copy(exif)
deltransposed_exif[0x0112]
print(exif[0x0112]) # it's still there, unmodified
The text was updated successfully, but these errors were encountered:
Thanks for the detailed analysis. I'll create PR to resolve this shortly, but I would also like to ask - I'm guessing you found this bug by opening an actual image file, right? If you don't want to attach that image, could you let us know the image format and the info dictionary? I'm interested in how the EXIF data was stored.
What did you do?
I used
ImageOps.exif_transpose
on an image with an EXIF orientation tag that should cause a rotation.What did you expect to happen?
Get a rotated
Image
with the EXIF orientation removed.What actually happened?
What are your OS, Python and Pillow versions?
Steps to reproduce
Possible fix
From some quick reading, I believe this line is the issue. The EXIF tags in a newly transposed image are empty:
But the method attempts to remove the orientation tag from this empty dictionary. It seems the change was made to avoid editing the EXIF tags of the original image (#5546), and using
copy.copy
would probably fix this:The text was updated successfully, but these errors were encountered: