Skip to content

Instantly share code, notes, and snippets.

@george-silva
Created May 8, 2014 18:06
Show Gist options
  • Save george-silva/e788a75307eea1c30e33 to your computer and use it in GitHub Desktop.
Save george-silva/e788a75307eea1c30e33 to your computer and use it in GitHub Desktop.
red
#!/usr/bin/env python
import os
import sys
import Image
EXTENSIONS = ".jpg", ".jpeg", ".png", ".bmp", ".tif"
SIZE = 1024, 768
def redimensionar_imagens(dir_):
for root, dirs, files in os.walk(dir_):
for file_ in files:
if file_.lower().endswith(EXTENSIONS):
path = os.path.join(root,file_)
try:
im = Image.open(path)
im.thumbnail(SIZE, Image.ANTIALIAS)
im.save(path)
except IOError as err:
print "[ERRO] ("+path+") "+err.strerror
if __name__ == "__main__":
dir_ = sys.argv[1]
redimensionar_imagens(dir_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment