Ticket #5525: 0001-Fix-EXIF-rotation-to-make-the-image-portrait-on-dema.patch

File 0001-Fix-EXIF-rotation-to-make-the-image-portrait-on-dema.patch, 1.4 KB (added by chrysn, 7 years ago)
  • mediagoblin/tools/exif.py

    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  
    1919from exifread import process_file
    2020from exifread.utils import Ratio
    2121
     22try:
     23    from PIL import Image
     24except ImportError:
     25    import Image
     26
    2227from mediagoblin.processing import BadMediaFail
    2328from mediagoblin.tools.translate import pass_to_ugettext as _
    2429
    def exif_fix_image_orientation(im, exif_tags):  
    6166    # Rotate image
    6267    if 'Image Orientation' in exif_tags:
    6368        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}
    6772        orientation = exif_tags['Image Orientation'].values[0]
    6873        if orientation in rotation_map:
    69             im = im.rotate(
     74            im = im.transpose(
    7075                rotation_map[orientation])
    7176
    7277    return im