if exif:
for tag in PIL.ExifTags.TAGS:
if PIL.ExifTags.TAGS[tag] == "Orientation":
- if exif[tag] == 3:
- image = image.rotate(180, expand=True)
- elif exif[tag] == 6:
- image = image.rotate(270, expand=True)
- elif exif[tag] == 8:
- image = image.rotate( 90, expand=True)
+ try:
+ if exif[tag] == 3:
+ image = image.rotate(180, expand=True)
+ elif exif[tag] == 6:
+ image = image.rotate(270, expand=True)
+ elif exif[tag] == 8:
+ image = image.rotate( 90, expand=True)
+
+ # Ignore if the orientation isn't encoded
+ except KeyError:
+ pass
# Remove any alpha-channels
if format == "JPEG" and not image.mode == "RGB":