我无法使用imagecopymerge函数实现图片的透明背景。

5

我正在调用imagecopymerge($dst_r, $logo, 0, 0, 0, 0, $LogoX, $LogoY, 100);,其中$logo是带有透明背景的png文件。但是不知何故,背景变成了白色。

我做错了什么?

谢谢。

2个回答

8

您需要使用imagealphablending($dst_r, TRUE);来允许在保留透明颜色的情况下进行复制。手册中有更多评论(...)建议使用imagecopy,因为imagecopymerge从未旨在与透明度一起使用。如果您仍然使用pct=100,那么正常的imagecopy可能是一个选项。


这里有一个具体的例子,请确保在创建PNG图像后调用imagealphablendingimagesavealpha链接 - dev.e.loper
使用imagecopy代替imagecopymerge解决了我的问题。 - croppio.com

-1

这是关于文本的,但你能理解我的意思。如果你发布整个代码会更有帮助。

$font = 25;
$string = "Hello";
$im = @imagecreatetruecolor(strlen($string) * $font / 1.5, $font);
imagesavealpha($im, true);
imagealphablending($im, false);
$white = imagecolorallocatealpha($im, 255, 255, 255, 127);
imagefill($im, 0, 0, $white);
$lime = imagecolorallocate($im, 204, 255, 51);
imagettftext($im, $font, 0, 0, $font - 3, $lime, "font.ttf", $string);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接