diff --git a/warehouse/models.py b/warehouse/models.py index f96c8c86e2c46d5a6347537a6f43d76ba8fc7d0b..67102e73fefe3ef94a013f617f45853c0a94e89a 100644 --- a/warehouse/models.py +++ b/warehouse/models.py @@ -6,6 +6,7 @@ import datetime from flask import current_app, send_file, Markup from flask_sqlalchemy import SQLAlchemy from PIL import Image +from PIL.ImageOps import exif_transpose db = SQLAlchemy() @@ -48,11 +49,12 @@ class Photo(db.Model): def send_thumbnail(self, max_width, max_height): path = os.path.join(current_app.config['UPLOAD_FOLDER'], self.path) buf = io.BytesIO() - with Image.open(path, formats=['JPEG']) as img: - scale = min(max_width/img.width, max_height/img.height) - img.thumbnail((int(img.width*scale), int(img.height*scale))) - img.save(buf, format='JPEG', quality=70) - buf.seek(0) + with Image.open(path, formats=['JPEG']) as img_orig: + with exif_transpose(img_orig) as img: + scale = min(max_width/img.width, max_height/img.height) + img.thumbnail((int(img.width*scale), int(img.height*scale))) + img.save(buf, format='JPEG', quality=70) + buf.seek(0) return send_file(buf, mimetype='image/jpeg') def token_typable():