imagepng() and transparency in GD library with PHP

Strawberry picture Strawberry · Nov 10, 2009 · Viewed 38.6k times · Source

When using the function imagepng() in PHP, how can I make sure the images that I save are saved with a transparent background?

Answer

mauris picture mauris · Nov 10, 2009

Simply do this:

imagealphablending($img, false);
imagesavealpha($img, true);

Before outputting. Make sure that all source files (if you used any) are set to PNG 32-bit with transparency - if not the output may differ with black background or transparency does not comply.