I use PHP and Imagick to change the color of a transparent PNG. The image in the PNG is a simple shape with a transparent background.
I use the colorizeImage function to change the color.
$img = new Imagick("shape.png");
$img->colorizeImage("#99ccff",0.0);
The problem is that Imagick show a dark version of my HEX code (#99ccff
)?
Is there a way to get the exact color (#99ccff
)?
(my PNG is PNG 32 - and the shape is black)
I thought I would answer this question despite that it is old. This is for anyone else having this problem.
I solved this for a project I am working on by simply using "Clut" instead, like so:
$img = new Imagick("shape.png");
$clut = new Imagick();
$clut->newImage(1, 1, new ImagickPixel('#99ccff'));
$img->clutImage($clut);
$clut->destroy();
Hope it helps anyone else having this issue.
$img = new Imagick("shape.png");
$img->colorizeImage("#99ccff",0.0);
That second parameter is opacity. If you set it to 1.0, it will match #99ccff 100%. You can set it to 0.5 to meet 50% over the original layer, etc:
$img = new Imagick("shape.png");
$img->colorizeImage("#99ccff", 1.0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With