Creating image thumbnails for jpegs using python

As the name says, I’m looking for a way to convert a huge number of images into thumbnails of different sizes. How do I do this in python

+5
source share
1 answer

See: http://www.pythonware.com/products/pil/index.htm

import os, sys
import Image

size = 128, 128

for infile in sys.argv[1:]:
    outfile = os.path.splitext(infile)[0] + ".thumbnail"
    if infile != outfile:
        try:
            im = Image.open(infile)
            im.thumbnail(size)
            im.save(outfile, "JPEG")
        except IOError:
            print "cannot create thumbnail for", infile
+15
source

All Articles