[omaha] The Python PIL

Mike Hostetler mike at hostetlerhome.com
Wed May 21 19:12:02 CEST 2008



Sometimes Python just amazes me . . .

I exported a bunch of
screens as JPEGs from one of the apps that I use and found out that I now
had 22 files that were 5500x5500.  And only the top-right corner was
filled out.  Ugh.

So I took a sampling and figured out
what box would contain every jpg, and grabbed the Imaging library:
http://www.pythonware.com/products/pil/

And wrote the
following:
import os,sys
from path import path
import
Image

box = (0,0,1000,750)

if
__name__=='__main__':

    inpath =
path("images")
    outpath =
path("images_smaller")

    for fname
in inpath.glob("*.jpg"):
        outname =
outpath/fname.name

       
img = Image.open(fname)
       
rect = img.crop(box)

       
rect.save(outname)


It took 30 seconds to run, and now I
have 22 images that are just the right size.


More information about the Omaha mailing list