Some pictures store the rotation of the picture in the EXIF data which
we ignored in the past.
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
#!/usr/bin/python3
+import PIL.ExifTags
import PIL.Image
import PIL.ImageFilter
import PIL.ImageOps
# Save image format
format = image.format
+ # Fetch any EXIF data
+ exif = image._getexif()
+
+ # Rotate the image
+ 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)
+
# Remove any alpha-channels
if image.format == "JPEG" and not image.mode == "RGB":
# Make a white background