analitics

Pages

Saturday, July 4, 2009

resize images to create thumbnails

First you have many images.
If you want to create thumbnail for each one this is python script:

import glob 
import PIL
from PIL import Image
for infile in glob.glob("*.jpg"):
 img = Image.open(infile)
 dim_percent=(100/float(img.size[0]))
 dim_size=int((float(img.size[1])*float(dim_percent)))
 img = img.resize((100,dim_size),PIL.Image.ANTIALIAS)
 if infile[0:2] != "trumb_":
  img.save("trumb_" + infile, "JPEG")