Skip to content

Instantly share code, notes, and snippets.

@hectorddmx
Created August 2, 2011 08:04
Show Gist options
  • Save hectorddmx/1119784 to your computer and use it in GitHub Desktop.
Save hectorddmx/1119784 to your computer and use it in GitHub Desktop.
How to generate thumbnails from existing jpg image files.
import glob
import Image
# HDB: set preferences here
source_extension = "*.jpg"
size = 110, 80
prefix = "t"
target_extension = "JPEG"
# get all the jpg files from the current folder
for infile in glob.glob(source_extension):
im = Image.open(infile)
# don't save if thumbnail already exists
if infile[0:2] != prefix:
# convert to thumbnail image
im.thumbnail(size, Image.ANTIALIAS)
# prefix thumbnail file with T_
im.save(prefix + infile, target_extension)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment