aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-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"