Never been to DZone Snippets before?

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

About this user

Matt Kaufman http://www.mattisbusy.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Create Image Thumbnails (Python)

   1  
   2  # experiments with the Python Image Library (PIL)
   3  
   4  # free from:  http://www.pythonware.com/products/pil/index.htm
   5  
   6  # create 128x128 (max size) thumbnails of all JPEG images in the working folder
   7  
   8  # Python23 tested    vegaseat    25feb2005
   9  
  10  
  11  import glob
  12  import Image
  13  
  14  # get all the jpg files from the current folder
  15  
  16  for infile in glob.glob("*.jpg"):
  17    im = Image.open(infile)
  18    # convert to thumbnail image
  19  
  20    im.thumbnail((128, 128), Image.ANTIALIAS)
  21    # don't save if thumbnail already exists
  22  
  23    if infile[0:2] != "T_":
  24      # prefix thumbnail file with T_
  25  
  26      im.save("T_" + infile, "JPEG")
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS