Skip to content

Instantly share code, notes, and snippets.

@paulocheque
Last active January 11, 2016 19:20
Show Gist options
  • Save paulocheque/f68ebe3b56168f8f5ded to your computer and use it in GitHub Desktop.
Save paulocheque/f68ebe3b56168f8f5ded to your computer and use it in GitHub Desktop.
image processing
import os
from os import listdir
from os.path import isfile, join
from invoke import run, task
dirpath = './mypath'
@task
def resize():
#http://www.imagemagick.org/Usage/resize/#resize
for filename in listdir(dirpath):
if isfile(join(dirpath, filename)):
prefix, extension = os.path.splitext(filename)
if extension in ('.jpg', '.jpeg', '.png', '.gif'):
run('convert {} -resize 200x200 {}_200x200{}'.format(os.path.join(dirpath, filename), os.path.join(dirpath, prefix), extension))
resize()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment