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
There seems to be a problem when uploading the same image.
filename.jpg
filename_th.jpg
the issue is the increment value for image:
filename_1.jpg
filename_th_1.jpg (should be filename_1_th.jpg)
Thanks for the hard work.