This script is written in python to perform EXFS corrections of digital photos. This script traverses the specified directory, stores all images, then performs the required transform to make the images display correctly.
#! /usr/bin/pythonimport timeimport osfrom random import randintimport pexiffrom PIL import Image, ExifTagsphoto_list = [] #List of all photo paths traversed by OS.WALKfor root, dirs, files in os.walk(“/yourpath/”):for file in files:if file.endswith(“.png”) or file.endswith(“.jpeg”) or file.endswith(“.jpg”) $# print(os.path.join(root, file)) #Debug for path checkingphoto_list.append(os.path.join(root, file)) #Add the current path+ph$for photo in photo_list:#print(“Try this: ” + photo)img = pexif.JpegFile.fromFile(photo)#print(photo + “<- Path Orient -> ” + str(img.exif.primary.Orientation[0]))try:image=Image.open(photo)for orientation in ExifTags.TAGS.keys():if ExifTags.TAGS[orientation]==’Orientation’:breakexif=dict(image._getexif().items())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(photo)image.close()except (AttributeError, KeyError, IndexError):# cases: image don’t have getexifprint(“broke”)