From fb2118a7217c92212ae0a428a12583dfec2a8399 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 6 Jan 2024 17:01:55 +0000 Subject: [PATCH] util: Don't fail if EXIF information is mission rotation Signed-off-by: Michael Tremer --- src/backend/util.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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": -- 2.47.3