我在我的一个项目中使用JCrop (用户必须裁剪他的脸),并将坐标和源图像发送到PHP处理程序。流程应该如下所示:基于接收到的坐标,处理程序裁剪图像,并使用imagecopy()将新创建的图像(在我的示例中为90x90)放在使用ImageCreateTrueColor()创建的空布局上。到目前为止,这个方法运行得很好,但下一步是:我必须加载一个带有透明部分的png图像。(我希望我解释得足够清楚),它的宽度和高度与之前的布局相同,上面有裁剪过的区域。最后一步是再次使用imagecopy()将png放在布局上,并将用户制作的透明部分覆盖的模板作为最终结果。下面是我的代码:
$targ_w = $targ_h = 90;
$jpeg_quality = 100;
$src = $_POST['s'];
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
$layout = ImageCreateTrueColor(459,683);
imagecopy($layout, $dst_r, 263, 249, 0, 0, 90, 90);
$template = 'template.png';
$src_r = imagecreatefrompng($template);
$background = imagecolorallocate($src_r, 255, 255, 255);
imagecolortransparent($src_r, $background);
imagealphablending($src_r, false);
imagesavealpha($src_r, true);
imagecopy($layout, $src_r, 0, 0, 0, 0, 459, 683);
header('Content-type: image/png');
imagepng($src_r);我尝试了很多在网上找到的东西,但似乎都不起作用。编辑:问题是透明部分是黑色的,而不是裁剪后的面。我真的需要一些建议。提前谢谢你。
发布于 2013-08-30 11:45:21
我以前写过一个类,它能解决你的问题吗?http://www.gdenhancer.com
这是example
https://stackoverflow.com/questions/15662885
复制相似问题