我正在调用imagecopymerge($dst_r, $logo, 0, 0, 0, 0, $LogoX, $LogoY, 100);
,其中$logo
是带有透明背景的png文件。但是不知何故,背景变成了白色。
我做错了什么?
谢谢。
我正在调用imagecopymerge($dst_r, $logo, 0, 0, 0, 0, $LogoX, $LogoY, 100);
,其中$logo
是带有透明背景的png文件。但是不知何故,背景变成了白色。
我做错了什么?
谢谢。
您需要使用imagealphablending($dst_r, TRUE);
来允许在保留透明颜色的情况下进行复制。手册中有更多评论(...)建议使用imagecopy
,因为imagecopymerge从未旨在与透明度一起使用。如果您仍然使用pct=100
,那么正常的imagecopy可能是一个选项。
这是关于文本的,但你能理解我的意思。如果你发布整个代码会更有帮助。
$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);
imagealphablending
和imagesavealpha
。链接 - dev.e.loper