class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
more info about the class
$foo = new upload('./my_pic.png'); $foo->image_watermark = 'watermark.png'; $foo->image_watermark_x = 10; $foo->image_watermark_y = 10; $foo->process('./test/');
It needs error handling, etc... but it shows how you can manipulate local files.