Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imagick colorizeImage Hex darker

Tags:

php

imagick

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)

http://www.2shared.com/photo/N3rGdoHG/shape3.html

like image 733
pelelive Avatar asked Nov 19 '11 07:11

pelelive


2 Answers

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.

like image 111
MrE Avatar answered Oct 14 '22 21:10

MrE


 $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);
like image 20
Authman Apatira Avatar answered Oct 14 '22 19:10

Authman Apatira