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
$handle = new upload($fname_original); if ($handle->uploaded) { //Get the new coordinates to crop the image. $x1 = $_POST["x1"]; $y1 = $_POST["y1"]; $x2 = $_POST["x2"]; $y2 = $_POST["y2"]; $w = $_POST["w"]; $h = $_POST["h"]; $handle->mime_check = true; $handle->allowed = array('image/*'); $handle->forbidden = array('application/*'); $handle->file_new_name_body = 'imagen_proy'; $handle->image_resize = true; $handle->image_x = 470; $handle->image_y = 470; $handle->image_precrop = array($y1, $handle->image_src_x - $x2, $handle->image_src_y - $y2, $x1); $handle->process($dir_pics); //thumbnail $handle->file_new_name_body = 'thhimagen_proy'; $handle->image_resize = true; $handle->image_ratio_x = true; $handle->image_y = 400; $handle->image_precrop = array($y1, $handle->image_src_x - $x2, $handle->image_src_y - $y2, $x1); $handle->process($dir_pics); $handle->clean(); } else { echo 'error : ' . $handle->error; }