Skip to content

Instantly share code, notes, and snippets.

@samuelclay
Created May 21, 2013 17:53
Show Gist options
  • Save samuelclay/5621805 to your computer and use it in GitHub Desktop.
Save samuelclay/5621805 to your computer and use it in GitHub Desktop.
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