天天看点

php 图片截取,PHP截取图片指定的某个区域

header("Content-type: image/jpeg");

$filename = 'book_rabbit_rule.jpg';

$im = imagecreatefromjpeg($filename);

$new_img_width = 120;

$new_img_height = 42;

$newim = imagecreate($new_img_width, $new_img_height);

// 输出图要从哪边开始 x, y ,原始图要从哪边开始 x, y ,要画多大 x, y(resize) , 要抓多大 x, y

imagecopyresampled($newim, $im, 0, 0, 7, 174, 120, 42, $new_img_width, $new_img_height);

// imagecopyresampled($newim, $im, 0, 0, 100, 30, 500, 500, $new_img_width, $new_img_height);

imagejpeg($newim);

imagedestroy($newim);

imagedestroy($im);

?>