diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2020-11-09 17:45:56 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2020-11-09 17:45:56 +0100 |
commit | 9abb06be301ccdacc4393873386c34d4f3721f7c (patch) | |
tree | e6f241659def3ab7aa6a9ad42f42a6ddb6bfa937 /fbin | |
parent | 4a202c2317658824e22e5ef31640cfa149e0b04b (diff) |
Rotate thumbnails if orientation is set
This fixes thumbnails being in the incorrect orientation after we
removed the call to mogrify.
Diffstat (limited to 'fbin')
-rwxr-xr-x | fbin/fbin.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/fbin/fbin.py b/fbin/fbin.py index 04857d9..c449a55 100755 --- a/fbin/fbin.py +++ b/fbin/fbin.py @@ -18,7 +18,7 @@ from urllib.parse import urlencode, urljoin from flask import Blueprint, redirect, current_app, url_for, request, render_template, session, flash, send_file, abort, jsonify, Markup, Response from flask_login import login_user, logout_user, current_user, login_required import jwt -from PIL import Image +from PIL import Image, ExifTags import requests from werkzeug.utils import secure_filename @@ -335,6 +335,15 @@ def thumb(hash): # Check for valid JPEG modes. if im.mode not in ('1', 'L', 'RGB', 'RGBX', 'CMYK', 'YCbCr'): im = im.convert('RGB') + e = im.getexif() + # Get orientation EXIF tag + orientation = e.get(274) + if orientation == 3: + im = im.rotate(180, expand=True) + elif orientation == 6: + im = im.rotate(270, expand=True) + elif orientation == 8: + im = im.rotate(90, expand=True) im.thumbnail(current_app.config.get('THUMB_SIZE', (128, 128)), Image.ANTIALIAS) im.save(ttf) except IOError: |