2011-04-03 53 views

回答

7

您需要使用imagealphablending($dst_r, TRUE);才能在保留透明色的情況下進行復印。本手冊中的許多more comments (...)建議使用imagecopy代替,因爲imagecopymerge從未打算與透明度一起使用。如果您仍然使用pct=100,那麼正常的圖像複製可能是一個選項。

+0

這裏是一個[具體示例](http://www.php.net/manual/en/function.imagecreatefrompng.php#85754)請確保調用'imagealphablending'和'imagesavealpha'創建後你的PNG圖像 – 2013-08-22 16:31:03

+0

使用imagecopy而不是imagecopymerge保存了我的一天 – 2017-01-10 12:14:34

0

這是用於文本,但您可以明白。如果你發佈完整的代碼會更有幫助。

$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);