in reply to Working with images

I have a script that I wrote for my own website that I think does what you're looking for. I made it available on my website, so you can see how it works and download it if you choose to.

http://www.ericmilford.com/download/scripts.shtml