imagecopymerge给了我黑暗的补丁

时间:2014-02-21 05:37:34

标签: php image gd imagecreatefrompng

我正在尝试合并两张图片。 featured7.png具有透明背景。但是最终的图像就像下面的黑色斑块:
enter image description here

以下是代码:请帮助:

$src = imagecreatefrompng('images/featured7.png');
$dest = imagecreatefromjpeg('images/1.jpg');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imageColorAllocateAlpha($dest, 0, 0, 0, 127);
imagecopymerge($dest, $src, 0, 0, 0, 0, 90, 90, 100);
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);

新修改的代码如下:但是除了小图像移动到更右边的中心之外,给出了相同的结果:

$img1 = imagecreatefrompng('images/featured7.png');
$img2 = imagecreatefrompng('images/1.jpg');
$image = imagecreatefromjpeg("images/1.jpg"); //
$image1 = imagecreatefrompng("images/featured7.png");//
$size = getimagesize("images/featured7.png");
$overlay = imagecreatetruecolor(80, 80);
$white = imagecolorallocate($overlay, 229, 229, 229);
imagefilledrectangle($overlay, 0, 0, 80, 80, $white);
imagecolortransparent($overlay,$white);  
imagecopy($overlay, $image1, (80-$size[0])/2, (80-$size[1])/2, 0, 0,   $size[0],$size[1]);
imagecopymerge($image, $image1, 280, 30, 0, 0, 80, 80, 100);
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);

以下是两张图片:
enter image description here
enter image description here

1 个答案:

答案 0 :(得分:1)

之前我遇到了同样的问题,我找到了解决方案,请在此处查看我的问题和答案:

PHP imagecopymerge source image's background change transparent to black 在你的情况下,样本使用这个:

$dit = imagecreatefromjpeg("./dst.jpg"); //
$source = imagecreatefrompng("./source.png");//
$size = getimagesize("./source.png");
imagecopy($dit, $source, 0,0, 0, 0, $size[0], $size[1]);
header('Content-Type: image/jpeg');
imagejpeg($dit);
imagedestroy($dit);

enter image description here