How to handle EXIF rotation
JHEAD
jhead -autorot *.jpeg/jpg
OR
jhead -autorot *Python
from PIL import Image, ExifTags
import os
folder = 'path_to_your_folder'
for image in os.listdir(folder):
print(image)
filepath = f"{folder}/{image}"
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
passLast updated

