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
What I could suggest is to call process() twice, so to create two thumbnails, and keep only the one you want (delete the one you don't want).
I will see if I can implement such a feature in the future to do it automatically.