Michał
Michał

Reputation: 31

IMG_FILTER_COLORIZE problems

I already got some great advice on the forums how to get the colorize function using imagefilter IMG_FILTER_COLORIZE.

The problem is that it doesn't work as I want it to work, the link below illustrates it best: http://expromo.pl/klienci/imagefilter/

I have a transparent png containing some kind of shape. I want to:

Here is my code:

$im = imagecreatefrompng('image.png');
imagealphablending($im, false);

if($im && imagefilter($im, IMG_FILTER_COLORIZE, 0,0,255,0))
{
    imagepng($im, 'image-new.png');
    imagedestroy($im);
}

On the link above: http://expromo.pl/klienci/imagefilter/

The first image is what I have. The second image is what I get, and the third image is what I want to get.

Big thanks in advance.

Upvotes: 2

Views: 4207

Answers (1)

Andronicus
Andronicus

Reputation: 1389

You must add imagesavealpha($im, true); so the alpha channel will be saved on the new image.

$im = imagecreatefrompng('image.png');
imagealphablending($im, false);

imagesavealpha($im, true);

if($im && imagefilter($im, IMG_FILTER_COLORIZE, 0,0,255,0)) {
    imagepng($im, 'image-new.png');
    imagedestroy($im);
}

Upvotes: 4

Related Questions