Created
May 21, 2013 17:53
-
-
Save samuelclay/5621805 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImageOps: | |
"""Module that holds all image operations. Since there's no state, | |
everything is a classmethod.""" | |
@classmethod | |
def adjust_image_orientation(cls, image): | |
"""Since the iPhone will store an image on its side but with EXIF | |
data stating that it should be rotated, we need to find that | |
EXIF data and correctly rotate the image before storage.""" | |
if hasattr(image, '_getexif'): | |
exif = image._getexif() | |
if exif: | |
for tag, value in exif.items(): | |
decoded = TAGS.get(tag, tag) | |
if decoded == 'Orientation': | |
if value == 6: | |
image = image.rotate(-90) | |
if value == 8: | |
image = image.rotate(90) | |
if value == 3: | |
image = image.rotate(180) | |
break | |
return image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment