From 9abb06be301ccdacc4393873386c34d4f3721f7c Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 9 Nov 2020 17:45:56 +0100 Subject: Rotate thumbnails if orientation is set This fixes thumbnails being in the incorrect orientation after we removed the call to mogrify. --- fbin/fbin.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'fbin') 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: -- cgit v1.2.3