I'm trying to create a transparent png image and layer various other pngs and jpgs to create a final png with transparency. I'm having trouble creating my initial empty transparent png. It currently has a white background.
Can anyone point me in the right direction. This is my code so far...
$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);
Transparency is not done in HTML, but is a part of the image itself. The browser will see the image as a PNG and display it as a PNG automatically. To add transparency to the image, you will have to edit the file with a graphics editor like Photoshop.
On the Picture Format tab, select Color, and then select Set Transparent Color. Click the color in the picture or image that you want to make transparent. Note: You can't make more than one color in a picture transparent.
Set imagealphablending($image,true);
on each new layer.
Try this:
<?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); ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With