phppngimagecreatefrompng

PHP imagecopy with transparent background


I use this code to create an image from another png image, the background is black by default. My question is how to set a transparent background?

$input = imagecreatefrompng('image.png');
$output = imagecreatetruecolor(50, 50);

imagecopy($output, $input, 4,0, 8,8, 8,8);
imagecopy... etc.

header('Content-Type: image/png');
imagepng($output);

Is there a easy way of doing this? Thanks


Solution

  • Sets the transparent color in the given image.

    int imagecolortransparent ( resource $image [, int $color ] )
    

    Here's the link