$height) { $dest_width = $max_width; $dest_height = round($max_width*$height/$width); } else { $dest_width = round($max_height*$width/$height); $dest_height = $max_height; } if(!$dest_image = imagecreatetruecolor($dest_width, $dest_height)){ die('{"error":"Could not create new image from source file."}'); } if($info[2]==IMAGETYPE_GIF||$info[2]==IMAGETYPE_PNG){ if($info[2]==IMAGETYPE_PNG){ imageAntiAlias($dest_image,true); } imagecolortransparent($dest_image, imagecolorallocatealpha($dest_image, 0, 0, 0,127)); imagealphablending($dest_image, false); imagesavealpha($dest_image, true); } if(!imagecopyresampled($dest_image, $source_image, 0, 0, $left, $top, $dest_width, $dest_height, max($width, $max_width), max($height, $max_height))){ die('{"error":"Could not crop the image with the provided coordinates."}'); } switch($info[2]) { case IMAGETYPE_GIF: if(!imagegif($dest_image, $target_file)){ die('{"error":"Could not save GIF file."}'); } break; case IMAGETYPE_PNG: if(!imagepng($dest_image, $target_file, max(9 - floor($quality/10),0))){ die('{"error":"Could not save PNG file."}'); } break; case IMAGETYPE_JPEG: if(!imagejpeg($dest_image, $target_file, $quality)){ die('{"error":"Could not save JPG file."}'); } break; } imagedestroy($dest_image); imagedestroy($source_image); //If we made it that far with no error, we can return a success message, with the thumb filename die('{"success":"'.$thumb.'"}'); ?>