Created
January 1, 2022 17:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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