Fixed indentation and added exception handler for when we dont find a orientation variable in the exif metadata.

This commit is contained in:
Kevin Midbøe
2019-04-15 22:19:06 +02:00
parent f297c244a4
commit 440ddd4503

View File

@@ -47,19 +47,24 @@ def processImage(file, outputPath=None):
} }
def rotateFromExifMetadata(image): def rotateFromExifMetadata(image):
for orientation in ExifTags.TAGS.keys(): try:
if ExifTags.TAGS[orientation]=='Orientation': for orientation in ExifTags.TAGS.keys():
break if ExifTags.TAGS[orientation]=='Orientation':
exif=dict(image._getexif().items()) break
exif=dict(image._getexif().items())
if exif[orientation] == 3: if exif[orientation] == 3:
image=image.rotate(180, expand=True) image=image.rotate(180, expand=True)
elif exif[orientation] == 6: elif exif[orientation] == 6:
image=image.rotate(270, expand=True) image=image.rotate(270, expand=True)
elif exif[orientation] == 8: elif exif[orientation] == 8:
image=image.rotate(90, expand=True) image=image.rotate(90, expand=True)
return image return image
except (AttributeError, KeyError, IndexError):
# cases: image don't have getexif
print('unable to find orientation exif metadata')
pass
def generateFilename(fileID, modifier, outputPath): def generateFilename(fileID, modifier, outputPath):
filename = "{}_{}.{}".format(fileID, modifier, OUTPUT_EXTENSION) filename = "{}_{}.{}".format(fileID, modifier, OUTPUT_EXTENSION)