/**
* аналог php-функции image_type_to_extension
*
* @param int $imagetype
* @return string
*/
function image_type_to_extension2($imagetype){
if(empty($imagetype)) return false;
switch($imagetype)
{
case IMAGETYPE_GIF: return 'gif';
case IMAGETYPE_JPEG: return 'jpeg';
case IMAGETYPE_PNG: return 'png';
case IMAGETYPE_WBMP: return 'wbmp';
default: return false;
}
}
/**
* Crop
*
* @param string $src
* @param int $x
* @param int $y
* @param int $w
* @param int $h
*/
function crop_img($src, $x, $y, $w, $h){
$image_params=getimagesize($src);
if (eval("\$src_img=imagecreatefrom".image_type_to_extension2($image_params[2])."('".$src."');")!==false){
$dest_img=imagecreatetruecolor($w, $h);
imagecopyresampled($dest_img, $src_img, 0, 0, $x, $y, $w, $h, $w, $h);
eval("image".image_type_to_extension2($image_params[2])."(\$dest_img, \$src, 100);");
}
}
crop_img("{$_SERVER['DOCUMENT_ROOT']}/001.JPG", 300, 200, 200, 200);