mirror of
https://github.com/KevinMidboe/leifs-image-processor.git
synced 2025-10-29 09:40:19 +00:00
Fixed indentation and added exception handler for when we dont find a orientation variable in the exif metadata.
This commit is contained in:
21
processor.py
21
processor.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user