One of Python’s many strengths is its large library of modules.

OK, so you may not be able to fly (well, maybe with that medicine…), but you can import antigravity now. It just opens up a Web browser with that comic in it.

In any case, what does this have to do with processing a bunch of images in Python? Well, there’s a handy module called PIL — the Python Imaging Library, that can do a number of interesting things to image files using just code. You can blur an image, resize it, save it as a different file type and more.

Unfortunately, most installs of Python don’t come with PIL installed by default. To remedy this, first download the source file, unzip it (you can use the command tar xvf Imaging-1.1.6.tar.gz on most *nix systems), change to the directory (cd Imaging-1.1.6) and run sudo python install.

If all goes according to plan, when you go into the Python interactive interpreter and type import Image, you shouldn’t get an error.

The Coderholic blog has a great post on how to do batch imagine processing using PIL. Check it out.

If you’re like me and you take a lot of screenshots using OSX’s built-in Grab application, you can see how you could write a script to process all of the resulting TIFF files into a JPEG format. Try it out for yourselves; I’ll post the code for how to do it in a day or so if nobody else does.



No Responses Yet to “PIL: Batch processing images in Python”  

  1. No Comments Yet

Leave a Reply