Well you did say "any suggestions" so here's mine:
Take a look at
kim here:
http://linux.softpedia.com/get/Multi...Kim-2263.shtml
It's not
php, it's a R-click service menu extension for KDE that does awesome things to images, or groups of images. It is just a front-end to some well-commented shell scripts, so it is easy to understand how it all works and modify to your liking. I am sure you could adapt parts of it to work with
php to achieve what you need.
kim requires the package
imagemagick which has the tools you'll need to do what you want.