我一直在尝试使用以下代码合并两个透明图像。基本图像是用作画布的完全透明图像。 我得到的结果如下图(第一张图片 - result.png)。如何让它完全透明?
function copyTransparent($src, $output, $srcWidth){
$x = 288;
$y = 85;
$bg = 'tranparent.png'; // fully transparent image as bg.
$margRight = abs(($x- $srcWidth)/2);
$img = imagecreatefrompng($bg);
imagealphablending($img, false);
imagesavealpha($img, true);
// Copy from other
imagecopy($img,$src, $margRight, 0, 0, 0, $x, $y);
// Save PNG
imagepng($img,$output,9);
imagedestroy($img);
}
$png = 'testSign2.png';
list($width,$height) = getimagesize($png);
$src = imagecreatefrompng($png);
$newHeight = 85;
$ratio = $width / $height;
$newWidth = ceil($newHeight*$ratio);
$newImage = resizePng($src, $newWidth, $newHeight);
copyTransparent($newImage,"result.png", $newWidth);