日期:2014-05-17  浏览次数:20466 次

php裁剪图片中的指定位置区域


想要裁剪的黄框区域内图片




裁剪后出错的图片


根据X Y指定坐标,截取图片指定宽高图片,现在用那个图片函数给出错了, 根据x y轴起点是对的, 但它把剩下的区域全部缩小,然后不足又加了黑边,导致图片变形了。

list($width,$heght,$type,$attr) = getimagesize($imgurl);
$thisimage = imagecreatetruecolor($new_w, $new_h);
$background = imagecolorallocate($thisimage, 255, 255, 255);
imagefilledrectangle($thisimage, 0, 0, $new_w, $new_h, $background);
$oldimg = imagecreatefromjpeg($imgurl);
imagecopyresampled($thisimage, $oldimg, 0, 0, $src_x, $src_y, $new_w, $new_h, $width, $heght);
header("Content-type: image/jpeg");
imagejpeg($thisimage);


请教下各位前辈,这个图片该怎么截取才能得到黄框中想要的图片呢

------解决方案--------------------
$thisimage = imagecreatetruecolor($new_w, $new_h);// $new_w, $new_h 为裁剪后的图片宽高
$oldimg = imagecreatefromjpeg($imgurl); // 载入原始图片
imagecopy($thisimage, $oldimg, 0, 0, $src_x, $src_y, $new_w, $new_h); //$src_y, $new_w 为原图中裁剪区域的左上角坐标

------解决方案--------------------
这个你图片的高度,宽度设置错了吧
剪切是没有问题的
------解决方案--------------------
参数是不是写错了啊?
------解决方案--------------------
探讨

$thisimage = imagecreatetruecolor($new_w, $new_h);// $new_w, $new_h 为裁剪后的图片宽高
$oldimg = imagecreatefromjpeg($imgurl); // 载入原始图片
imagecopy($thisimage, $oldimg, 0, 0, $src_x, $src_y, $new_w, $new_h);……