From: chrysn <guest@hephaistos.amsuess.com>
Date: Wed, 30 Aug 2017 20:59:32 +0000 (+0200)
Subject: Fix EXIF rotation to make the image portrait on demand
X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=98340b6d03eea10cf1806077a10e5eff3b85aa02;p=mediagoblin.git

Fix EXIF rotation to make the image portrait on demand

Closes: https://issues.mediagoblin.org/ticket/5525
Signed-off-by: Andrew Browning <ayleph@thisshitistemp.com>
---

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