]> git.ipfire.org Git - ipfire.org.git/commitdiff
util: Don't fail if EXIF information is mission rotation
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Jan 2024 17:01:55 +0000 (17:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Jan 2024 17:01:55 +0000 (17:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/util.py

index 27290cc499200e90920c455d10a2388a31daa779..f6285c02a134aecb9fee274e49799f1f8119f2b3 100644 (file)
@@ -232,12 +232,17 @@ def generate_thumbnail(image, size, square=False, format=None, **args):
        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":