Skip to content

Instantly share code, notes, and snippets.

@lepture
Created July 1, 2013 10:56
Show Gist options
  • Save lepture/5899948 to your computer and use it in GitHub Desktop.
Save lepture/5899948 to your computer and use it in GitHub Desktop.
Rotate it right for browser displaying images.
# coding: utf-8
def fix_orientation(img):
orientation = img.metadata.get('exif:Orientation', 1)
if orientation == 1:
# do nothing
return img
elif orientation == 2:
# vertical mirror
img.flop()
elif orientation == 3:
img.rotate(180)
elif orientation == 4:
# horizontal mirror
img.flip()
elif orientation == 5:
img.flip()
img.rotate(270)
elif orientation == 6:
img.rotate(270)
elif orientation == 7:
img.flop()
img.rotate(270)
elif orientation == 8:
img.rotate(90)
return img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment