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.
I think that the class is not really the good tool for that. You could probably use the watermark feature of the class to achieve your goal, calling process() 4 times. But you will loose some quality each time.
You should use Imagemagick. See for instance this page.