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
Or else, you can just use the example provided in the package: when you upload an image, it does process it twice, which is what you want.
You can adapt either piece of code to suit your needs. There should be enough indications to get you going.