PHP imagecopy with transparent background

2by picture 2by · Oct 11, 2011 · Viewed 30.5k times · Source

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

Answer

Wazy picture Wazy · Oct 11, 2011

Sets the transparent color in the given image.

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

Here's the link