summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfbin/fbin.py11
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: