The-Last-Escape Posted April 30, 2007 Share Posted April 30, 2007 I've been working on something which takes multiple PNG Transparent images and layers them on top of each other to make another transparent image. So far it kind or works, however the background turns completely black and I'm not sure what to do from here. So my main question is, how do I make a transparent background without killing my antialising (I don't want to set a transparent color and place that color as background)? HERE IS MY CODE: $im = @imagecreatetruecolor(200, 200) or die("Cannot Initialize new GD image stream"); // Loading Images $red = imagecreatefrompng("red.png"); imagealphablending($red, true); imagesavealpha($red, true); $blue = imagecreatefrompng("blue.png"); imagealphablending($blue, true); imagesavealpha($blue, true); $green = imagecreatefrompng("green.png"); imagealphablending($green, true); imagesavealpha($green, true); // Flattening layers imagecopy($blue, $red, 0, 0, 0, 0, 200, 200); imagecopy($green, $blue, 0, 0, 0, 0, 200, 200); imagecopy($im, $green, 0, 0, 0, 0, 200, 200); imagealphablending($im, true); imagesavealpha($im, true); // Save image to disc imagepng($im, "final.png"); // Deallocate memory of image imagedestroy($im); Link to comment https://forums.phpfreaks.com/topic/49357-gd2-help/ Share on other sites More sharing options...
obsidian Posted April 30, 2007 Share Posted April 30, 2007 The best help I've found with this is the imagecolortransparent() function. The first comment on the manual page has this handy advice: When you use palette images (created with imagecreate()), the first color allocated is the background color. This color cannot be used for transparency. So if you want to make the background transparent, first allocate a dummy background color, then allocate the real background color and declare this is as transparent. One other note worth your reading: Note: Transparency is copied only with imagecopymerge() and true color images, not with imagecopy() or pallete images. Try using your imagecopymerge() instaed of imagecopy() for what you're doing, too. Hope this helps. Link to comment https://forums.phpfreaks.com/topic/49357-gd2-help/#findComment-241846 Share on other sites More sharing options...
The-Last-Escape Posted April 30, 2007 Author Share Posted April 30, 2007 Thank you Link to comment https://forums.phpfreaks.com/topic/49357-gd2-help/#findComment-241858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.