Last active
December 11, 2015 08:09
-
-
Save glenfant/4571612 to your computer and use it in GitHub Desktop.
Hint to David Hernandez
This file contains hidden or 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
import os | |
from PIL import Image | |
# Prefer the r"xxx" notation when you have backslashes | |
pathe = r"C:\David\" | |
for (path, dirs, files) in os.walk(pathe): | |
print path | |
print dirs | |
print files | |
for archivo in files: | |
print os.path.abspath(archivo) | |
f, e = os.path.splitext(archivo) | |
# We should ignore .jpg files to avoid IO errors and others | |
if e.lower() in ('.jpg', '.jpeg'): | |
continue | |
# Make the path of outfile otherwise it goes to root | |
infile = os.path.join(path, archivo) | |
outfile = os.path.join(path, f + ".jpg") | |
# There may be errors when stuffing images | |
try: | |
im = Image.open(infile) | |
im.save(outfile) | |
except Exception as exc: | |
print "Error when transforming", infile | |
print exc | |
print "--" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment