resize

Christian Harms's picture

Image resizing tips general and for python

Generating thumbnails from a collection of pictures is an easy task and there are many tools for the job. But I didn't find a tool who can clip out a centered box of my pictures to get quadratic thumbs of my originals. Because I am a developer and I dont want to try out many tools: I will hack a short python script (with help of the PIL) myself.

simple solution

The following python script can be find on many webpages. It will take all command line arguments as image filenames and convert it to 200x200 thumbnails with the default extension "_thumb.jpg" (build from the original filename):

  1. import Image, os, sys
  2.  
  3. for filename in sys.argv[1:]:
  4.     img = Image.open(filename).resize( (200,200) )
  5.     out = file(os.path.splitext(filename)[0]+"_thumb.jpg", "w")
  6.     try:
  7.         img.save(out, "JPEG")
  8.     finally:
  9.         out.close()
Read more

Syndicate content