Skip to content

Instantly share code, notes, and snippets.

@cfra
Created November 8, 2015 08:42
Show Gist options
  • Save cfra/a78150000d2fa9431818 to your computer and use it in GitHub Desktop.
Save cfra/a78150000d2fa9431818 to your computer and use it in GitHub Desktop.
from PIL import Image
img = Image.open(image_path)
if orientation == 2:
img = img.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 3:
img = img.transpose(Image.ROTATE_180)
elif orientation == 4:
img = img.transpose(Image.FLIP_TOP_BOTTOM)
elif orientation == 5:
img = img.transpose(Image.ROTATE_270)
img = img.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 6:
img = img.transpose(Image.ROTATE_270)
elif orientation == 7:
img = img.transpose(Image.ROTATE_90)
img = img.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 8:
img = img.transpose(Image.ROTATE_90)
img.save(self.image.path, "JPEG", quality=95, optimize=True, progressive=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment