From 98340b6d03eea10cf1806077a10e5eff3b85aa02 Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 30 Aug 2017 22:59:32 +0200 Subject: [PATCH] Fix EXIF rotation to make the image portrait on demand Closes: https://issues.mediagoblin.org/ticket/5525 Signed-off-by: Andrew Browning --- mediagoblin/tools/exif.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mediagoblin/tools/exif.py b/mediagoblin/tools/exif.py index a428ddf1..2215fb0c 100644 --- a/mediagoblin/tools/exif.py +++ b/mediagoblin/tools/exif.py @@ -19,6 +19,11 @@ import six from exifread import process_file from exifread.utils import Ratio +try: + from PIL import Image +except ImportError: + import Image + from mediagoblin.processing import BadMediaFail from mediagoblin.tools.translate import pass_to_ugettext as _ @@ -61,12 +66,12 @@ def exif_fix_image_orientation(im, exif_tags): # Rotate image if 'Image Orientation' in exif_tags: rotation_map = { - 3: 180, - 6: 270, - 8: 90} + 3: Image.ROTATE_180, + 6: Image.ROTATE_270, + 8: Image.ROTATE_90} orientation = exif_tags['Image Orientation'].values[0] if orientation in rotation_map: - im = im.rotate( + im = im.transpose( rotation_map[orientation]) return im -- 2.25.1