Skip to content

Instantly share code, notes, and snippets.

@glenfant
Last active December 11, 2015 08:09
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 glenfant/4571612 to your computer and use it in GitHub Desktop.
Save glenfant/4571612 to your computer and use it in GitHub Desktop.
Hint to David Hernandez
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