Skip to content

Instantly share code, notes, and snippets.

@codeif
Created November 23, 2018 08:40
Show Gist options
  • Save codeif/4a31fe911c072cc983de71cbad71189e to your computer and use it in GitHub Desktop.
Save codeif/4a31fe911c072cc983de71cbad71189e to your computer and use it in GitHub Desktop.
def get_right_img(image):
# https://stackoverflow.com/a/6218425/7403042
if not hasattr(image, '_getexif'):
return image
image_exif = image._getexif()
if not image_exif:
return image
image_orientation = image_exif[274]
# Rotate depending on orientation.
if image_orientation == 3:
image = image.rotate(180, expand=True)
elif image_orientation == 6:
image = image.rotate(-90, expand=True)
elif image_orientation == 8:
image = image.rotate(90, expand=True)
return image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment