I have the following scenario:
I am using pyexiv2 for EXIF manipulation.
Issue: The EXIF information incluiding the thumbnails lost while rotating the image using wxpython.
What I did: I am reading the EXIF before rotating the image. I reset the orientation field in the EXIF. Then I am putting it back after rotation.
The problem:
The thumbnail inside the EXIF is not rotated. So, the image and thumbnail have different orientations.
Questions?
Is there any module other than PIL to rotate an image keeping its EXIF info?
Is there a separate EXIF field for thumbnail orientation?
Is there a way I can just rotate the Thumbnail alone?
Thanks for your help...
This solution works for me: PIL thumbnail is rotating my image?
Don't need to check if it's iPhone or iPad: if photo has orientation tag – rotate it.
from PIL import Image, ExifTags
try:
image=Image.open(filepath)
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation]=='Orientation':
break
exif = image._getexif()
if exif[orientation] == 3:
image=image.rotate(180, expand=True)
elif exif[orientation] == 6:
image=image.rotate(270, expand=True)
elif exif[orientation] == 8:
image=image.rotate(90, expand=True)
image.save(filepath)
image.close()
except (AttributeError, KeyError, IndexError):
# cases: image don't have getexif
pass
Before:
After: