我打電話imagecopymerge($dst_r, $logo, 0, 0, 0, 0, $LogoX, $LogoY, 100);
其中$logo
是一個背景透明的PNG文件。出於某種原因,背景變爲白色。我不能使用透明背景與imagecopymerge
我在做什麼錯?
謝謝。
我打電話imagecopymerge($dst_r, $logo, 0, 0, 0, 0, $LogoX, $LogoY, 100);
其中$logo
是一個背景透明的PNG文件。出於某種原因,背景變爲白色。我不能使用透明背景與imagecopymerge
我在做什麼錯?
謝謝。
您需要使用imagealphablending($dst_r, TRUE);
才能在保留透明色的情況下進行復印。本手冊中的許多more comments (...)建議使用imagecopy
代替,因爲imagecopymerge從未打算與透明度一起使用。如果您仍然使用pct=100
,那麼正常的圖像複製可能是一個選項。
這是用於文本,但您可以明白。如果你發佈完整的代碼會更有幫助。
$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);
這裏是一個[具體示例](http://www.php.net/manual/en/function.imagecreatefrompng.php#85754)請確保調用'imagealphablending'和'imagesavealpha'創建後你的PNG圖像 – 2013-08-22 16:31:03
使用imagecopy而不是imagecopymerge保存了我的一天 – 2017-01-10 12:14:34