My wife and I were married just over a month ago, and we have some friends who are a wedding photographer/videographer extraordinaire couple. We got our proofs from them on a DVD this week, and I've been struggling to work with them. I don't own one of those fancy schmancy iMacs with 1,182,756,418,237,645,183,645GB of RAM in them, and these pictures are HUMOUNGUS (5MB average). So, obviously, when I get ten of those pictures open, my laptop's system resources take a hit. How 'bout uploading them to my webserver? Fuhget about it! There's a good 375 of them, so it's well over 1GB of data. And why should I make my parents suffer for looking at my wedding photos over the net instead of in person (though they live 20 minutes away...)
As I struggled with dealing with such great Megapixelage, I found a solution: The Python Imaging Library. Unlike some Python libraries, I found that this library had lots of documentation, and I was able to figure out what I wanted to do quickly. For the most part, shrinking the images to 50% was all I really needed to do. So I wrote up this Python script. Although I didn't need to use os.walk, I thought implementing it would make it easier for me to re-use later.
import os, Image
def half( im ):
newWidth = im.size
newHeight = im.size
return im.resize((newWidth, newHeight ) ) #The size needs to pass as a tuple
srcDir = '/path/to/src'
saveDir = '/path/to/dest'
for a, b, c,in os.walk( srcDir ):
for image in c:
imgName = image[1:-4] #trim the extension
resizeName ='%s/%s_small.jpg' % ( saveDir, imgName )
im = Image.open( '%s/%s' % ( a, image ) )
im = half( im )
im.save( resizedName, 'JPEG' )Now all my images are half the size. Hooray!