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):
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation]=='Orientation':
break
exif=dict(image._getexif().items())
try:
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation]=='Orientation':
break
exif=dict(image._getexif().items())
if exif[orientation] == 3:
if exif[orientation] == 3:
image=image.rotate(180, expand=True)
elif exif[orientation] == 6:
elif exif[orientation] == 6:
image=image.rotate(270, expand=True)
elif exif[orientation] == 8:
elif exif[orientation] == 8:
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):
filename = "{}_{}.{}".format(fileID, modifier, OUTPUT_EXTENSION)