我正在尝试创建透明的png图像,并对其他各种png和jpg进行分层,以创建具有透明度的最终png。我在创建初始的空透明png时遇到问题。目前有白色背景。
谁能指出我正确的方向。到目前为止,这是我的代码…
$image = imagecreatetruecolor(485, 500); imagealphablending($image, false); imagesavealpha($image, true); $col=imagecolorallocatealpha($image,255,255,255,127); imagefill($image, 0, 0, $col); //imagefilledrectangle($image,0,0,485, 500,$col); /* add door glass */ $img_doorGlass = imagecreatefrompng("glass/$doorStyle/$doorGlass.png"); imagecopyresampled($image, $img_doorGlass, 106, 15, 0, 0, 185, 450, 185, 450); /* add door */ $img_doorStyle = imagecreatefrompng("door/$doorStyle/$doorStyle"."_"."$doorColor.png"); imagecopyresampled($image, $img_doorStyle, 106, 15, 0, 0, 185, 450, 185, 450); $fn = md5(microtime()."door_builder").".png"; if(imagepng($image, "user_doors/$fn", 1)){ echo "user_doors/$fn"; } imagedestroy($image);
imagealphablending($image,true);在每个新图层上设置。
imagealphablending($image,true);
尝试这个:
<?php $image = imagecreatetruecolor(485, 500); imagealphablending($image, false); $col=imagecolorallocatealpha($image,255,255,255,127); imagefilledrectangle($image,0,0,485, 500,$col); imagealphablending($image,true); /* add door glass */ $img_doorGlass = imagecreatefrompng("glass/$doorStyle/$doorGlass.png"); imagecopyresampled($image, $img_doorGlass, 106, 15, 0, 0, 185, 450, 185, 450); imagealphablending($image,true); /* add door */ $img_doorStyle = imagecreatefrompng("door/$doorStyle/$doorStyle"."_"."$doorColor.png"); imagecopyresampled($image, $img_doorStyle, 106, 15, 0, 0, 185, 450, 185, 450); imagealphablending($image,true); $fn = md5(microtime()."door_builder").".png"; imagealphablending($image,false); imagesavealpha($image,true); if(imagepng($image, "user_doors/$fn", 1)){ echo "user_doors/$fn"; } imagedestroy($image); ?>