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
Warning: imagejpeg(): supplied argument is not a valid Image resource
For some reason PHP does not like the file contents generated by the statement $img = $foo->process();
Any suggestions?