我正在尝试使用PHP合并两个透明图像,但是图像有一些黑色边框和斑点,我无法找出问题所在。以下是我的附加代码:
$image1=$image2='imagepath.png';
imagealphablending($image2, true);
imagesavealpha($image2, true);
$w=imagesx($image1);
$h=imagesy($image1);
$final = imagecreatetruecolor($w, $h);
$black = imagecolorallocate($final, 0, 0, 0);
$backgroundColor = imagecolortransparent($final, $black);
$percent = 0.583;
$new_width = $w * $percent;
$new_height = $h * $percent;
$wshift = $w/8.5;
$hshift = $h/2.5;
imagecopy($final, $image1, 0,0,0,0,$w,$h);
imagecopyresized($final, $image2,$wshift,$hshift,0,0, $new_width, $new_height, $w, $h);
header('Content-Type: image/png');
imagepng($final);
imagedestroy($image2);
imagedestroy($image1);
imagedestroy($final);
示例测试:
查看演示:http://goo.gl/qMWNB4
图片链接:http://goo.gl/pR59MT
imagecopymerge
可能会有一点帮助。http://php.net/manual/zh/function.imagecopymerge.php - Michas