From 67c276758c15970dbb2b80a0fc80969e5715e52c Mon Sep 17 00:00:00 2001
From: chrysn <guest@hephaistos.amsuess.com>
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
---
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 fafd987d..b6ba75ae 100644
a
|
b
|
import six
|
19 | 19 | from exifread import process_file |
20 | 20 | from exifread.utils import Ratio |
21 | 21 | |
| 22 | try: |
| 23 | from PIL import Image |
| 24 | except ImportError: |
| 25 | import Image |
| 26 | |
22 | 27 | from mediagoblin.processing import BadMediaFail |
23 | 28 | from mediagoblin.tools.translate import pass_to_ugettext as _ |
24 | 29 | |
… |
… |
def exif_fix_image_orientation(im, exif_tags):
|
61 | 66 | # Rotate image |
62 | 67 | if 'Image Orientation' in exif_tags: |
63 | 68 | rotation_map = { |
64 | | 3: 180, |
65 | | 6: 270, |
66 | | 8: 90} |
| 69 | 3: Image.ROTATE_180, |
| 70 | 6: Image.ROTATE_270, |
| 71 | 8: Image.ROTATE_90} |
67 | 72 | orientation = exif_tags['Image Orientation'].values[0] |
68 | 73 | if orientation in rotation_map: |
69 | | im = im.rotate( |
| 74 | im = im.transpose( |
70 | 75 | rotation_map[orientation]) |
71 | 76 | |
72 | 77 | return im |