From f1a878cbc68bd7357d12cb3de4a3d86b6c635835 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Mon, 12 Aug 2024 01:07:07 -0400 Subject: Handle EXIF rotation information when generating thumbnail. --- utils/postutil.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'utils') diff --git a/utils/postutil.py b/utils/postutil.py index 86bd472..1ac32c3 100644 --- a/utils/postutil.py +++ b/utils/postutil.py @@ -57,6 +57,24 @@ def generate_thumbnail(file): with Image(filename=file) as i: if i.height <= dim and i.width <= dim and i.format.lower() != "png": return None + if "exif:Orientation" in i.metadata: + o = int(i.metadata['exif:Orientation'][:1]) + match o: + case 0: pass + case 1: pass + case 2: i.flop() + case 3: i.rotate(180) + case 4: + i.flop() + i.rotate(180) + case 5: + i.flip() + i.rotate(90) + case 6: i.rotate(90) + case 7: + i.flip() + i.rotate(270) + case 8: i.rotate(270) s = dim / max(i.height, i.width) i.resize(int(i.width * s), int(i.height * s), "lanczos2") i.format = "webp" -- cgit v1.2.3