DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Create Image Thumbnails (Python)

  • submit to reddit
# experiments with the Python Image Library (PIL)

# free from:

# create 128x128 (max size) thumbnails of all JPEG images in the working folder

# Python23 tested    vegaseat    25feb2005

import glob
import Image

# get all the jpg files from the current folder

for infile in glob.glob("*.jpg"):
  im =
  # convert to thumbnail image

  im.thumbnail((128, 128), Image.ANTIALIAS)
  # don't save if thumbnail already exists

  if infile[0:2] != "T_":
    # prefix thumbnail file with T_"T_" + infile, "JPEG")