【发布时间】:2019-08-01 22:33:47
【问题描述】:
我有两张图片要合并,它们的大小都是 150x150 像素。
我想将它们合并成一个 225 宽 x 150 高的新图像。所以图片 2 覆盖了图片 1 的一半。
我做了一些代码,但透明度只适用于 150x150 的新图像,其余的只是黑色背景。
两张图片都有透明背景。
background.png 只是一个大小为 225x150 像素的 png 文件,具有透明背景。
我做错了什么?
$width = "225";
$height = "150";
$dest_image = imagecreatefrompng('background.png');
imagesavealpha($dest_image, true);
$trans_background = imagecolorallocatealpha($dest_image, 0, 0, 0, 127);
imagefill($dest_image, 0, 0, $trans_background);
$a = imagecreatefrompng('9.png');
$b = imagecreatefrompng('90.png');
imagecopy($dest_image, $a, 0, 0, 0, 0, $width, $height);
imagecopy($dest_image, $b, 75, 0, 0, 0, $width, $height);
header('Content-Type: image/png');
imagepng($dest_image);
imagedestroy($a);
imagedestroy($b);
imagedestroy($dest_image);
【问题讨论】: