php裁剪图片中的指定位置区域,该怎么解决

WBOY
Release: 2016-06-13 13:37:09
Original
1306 people have browsed it

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);……
Related labels:
new
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template