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
http://tinypic.com/r/300b320/9
After upload
http://tinypic.com/r/zk65h3/9
Script
// save uploaded image with no changes
$img_class->file_new_name_body = $image_name;
$img_class->image_resize = false;
$img_class->image_ratio_crop = false;
// save to root $path
if ($key_w == '358' && $value_h == '358'){// to 500x492 folder
$img_class->image_resize = true;
$img_class->image_x = $key_w;
$img_class->image_y = $value_h;
// fit image to specific size
$img_class->image_ratio_crop = true;
// no image part, set background color
//$img_class->image_background_color = '#fff';
}elseif($key_dir == 'b'){ // to b folder
$img_folder = $key_dir.'/';
}else{// save to *x* folder
$img_class->image_resize = true;
$img_class->image_x = $key_w;
$img_class->image_y = $value_h;
// crop image
$img_class->image_ratio_crop = true;
$img_folder = $key_dir.'/';
}
//$img_class->image_ratio_fill = true;
//$img_class->image_background_color = '#fff';
$img_class->file_overwrite = true;
$img_class->dir_auto_create = true;
$img_class->Process($_SERVER['DOCUMENT_ROOT'].'/Uploads/'.$path.'/'.$img_folder);
if ($img_class->processed) {/*echo 'original image copied'; echo $img_class->file_dst_name;*/} else {echo 'error : ' . $img_class->error;}