For a project at work I had to create a true colour PNG from scratch using GD, copy a load of image files to it from various locations and then display it on-screen. The code to create a transparent PNG turned out to be a litle complicated:
// create a true colour, transparent image
// turn blending OFF and draw a background rectangle in our transparent colour
// ^^ Alpha blanding is back on.
// insert image manipulation stuff in here
// output the results...
Important Note: If you output the image direct into the document stream as this example does, the PNG fix that uses bahaviours won’t work as it’s not a true PNG. For that, you’ll have to drop the header and give imagepng() a filename and show that file. Seems to work fine in other browsers, however.
Originally Posted: 27th March 2007