aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2024-08-12 01:07:07 -0400
committerGravatar Chris Xiong <chirs241097@gmail.com> 2024-08-12 01:07:07 -0400
commitf1a878cbc68bd7357d12cb3de4a3d86b6c635835 (patch)
tree9a79ca319c70434dfe16354bc04358ae66b92da7
parentdae2af0bf4bbc87076dbb6ba378a8f018dab2e26 (diff)
downloadnotekins-f1a878cbc68bd7357d12cb3de4a3d86b6c635835.tar.xz
Handle EXIF rotation information when generating thumbnail.
-rw-r--r--utils/postutil.py18
1 files changed, 18 insertions, 0 deletions
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"