Monday, September 06, 2004

Resizing images in python

# resize.py
# Simply put the file into the directory of images
# and run.
#
# A directory called resized is created, into which
# the resized images are put
#
# resizeFactor of 0.5 redueces the height and width
# by half

import Image
import glob
import os
from os.path import join

resizeFactor = 0.5

if not os.path.isdir("resized"):
    os.mkdir("resized")

for i in glob.glob("*.jpg"):
    im = Image.open(i)
    width, height = im.size
    print join("resized", i)
    im.resize((int(width*resizeFactor),
              int(height*resizeFactor))).save(join(os.curdir, "resized", i))
    

0 Comments:

Post a Comment

<< Home