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
image_src_x image_src_y image_src_bits, image_src_pixels image_src_type
Instantiate the class first, and then if $foo->uploaded == true, you can read the following variables:
Then, you can call $foo->process() with different parameters, depending on the variables above.
Note that this will not work if open_basedir restrictions are in place.