【发布时间】:2011-07-28 14:37:48
【问题描述】:
我正在调用imagecopymerge($dst_r, $logo, 0, 0, 0, 0, $LogoX, $LogoY, 100);,其中$logo 是具有透明背景的png 文件。由于某种原因,背景变成了白色。
我做错了什么?
谢谢。
【问题讨论】:
标签: php image-manipulation gd
我正在调用imagecopymerge($dst_r, $logo, 0, 0, 0, 0, $LogoX, $LogoY, 100);,其中$logo 是具有透明背景的png 文件。由于某种原因,背景变成了白色。
我做错了什么?
谢谢。
【问题讨论】:
标签: php image-manipulation gd
您需要使用imagealphablending($dst_r, TRUE); 以允许在保留透明颜色的情况下进行复制。手册中的许多 more comments (...) 建议改用 imagecopy,因为 imagecopymerge 从未打算与透明度一起使用。如果您仍然使用pct=100,那么普通的图像复制可能是一种选择。
【讨论】:
imagealphablending 和 imagesavealpha
这是针对文本的,但您可以明白这一点。如果您发布整个代码会更有帮助。
$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);
【讨论】: