Here's the docs for the imagemagick command line tools. If had a bit more time I'd actually get into the php api to see what they have.
http://www.imagemagick.org/script/composite.php
Im pretty sure you can also use the GD libs in php to get this done.