我有一個透明背景的PNG水印圖像。但隨機產生一個白色的背景,而不是保持透明。GD:使PNG透明的白色背景
// Watermark
$watermark = imagecreatefrompng($docRoot . '/images/misc/watermark.png');
list($mwidth, $mheight) = getimagesize($docRoot . '/images/misc/watermark.png');
// Combinde watermark image with image already generated in $dst
imagecopy($dst, $watermark, $tnWidth-$mwidth-5, $tnHeight-$mheight-5, 0, 0, $mwidth, $mheight);
解決方案是增加:
imagealphablending($dst, true);
imagesavealpha($dst, true);
完整代碼:
// Watermark
$watermark = imagecreatefrompng($docRoot . '/images/misc/watermark.png');
list($mwidth, $mheight) = getimagesize($docRoot . '/images/misc/watermark.png');
imagealphablending($dst, true);
imagesavealpha($dst, true);
// Combinde watermark image with image already generated in $dst
imagecopy($dst, $watermark, $tnWidth-$mwidth-5, $tnHeight-$mheight-5, 0, 0, $mwidth,
只需添加imagealphablending($ dst,true); imagesavealpha($ dst,true);訣竅。感謝您讓我走上正軌。 – Cudos 2010-11-12 10:01:09