From: Michael Tremer Date: Sat, 6 Jan 2024 17:01:55 +0000 (+0000) Subject: util: Don't fail if EXIF information is mission rotation X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fb2118a7217c92212ae0a428a12583dfec2a8399;p=ipfire.org.git util: Don't fail if EXIF information is mission rotation Signed-off-by: Michael Tremer --- diff --git a/src/backend/util.py b/src/backend/util.py index 27290cc4..f6285c02 100644 --- a/src/backend/util.py +++ b/src/backend/util.py @@ -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":