问题
I am calling imagecopymerge($dst_r, $logo, 0, 0, 0, 0, $LogoX, $LogoY, 100);
where $logo
is a png file with transparent background. From some reason the background comes out white instead.
What am I doing wrong?
Thanks.
回答1:
You need to use imagealphablending($dst_r, TRUE); to allow copying with retaining the transparent colors. Many more comments (...) in the manual suggest using imagecopy
instead, because imagecopymerge was never intended to be used with transparency. If you use pct=100
anyway, then the normal imagecopy might be an option.
回答2:
This is for text, but you can get the point. It would be more helpful if you post entire code.
$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);
来源:https://stackoverflow.com/questions/5529306/i-cant-use-transparent-background-with-imagecopymerge