Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subins2000/bd90c2d7e09bef169720aae41d59ac23 to your computer and use it in GitHub Desktop.
Save subins2000/bd90c2d7e09bef169720aae41d59ac23 to your computer and use it in GitHub Desktop.
Fixes the rotation of images in a folder by their EXIF orientation property. Useful for Wikimedia Commons uploads
#!/usr/bin/env python3
import glob
import sys
from PIL import ImageOps, Image
dirpath = sys.argv[1]
try:
images = glob.glob(dirpath + "/*.jpg")
for filepath in images:
image = Image.open(filepath)
image = ImageOps.exif_transpose(image)
image.save(filepath)
image.close()
except (AttributeError, KeyError, IndexError):
# cases: image don't have getexif
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment