Page 1 of 1
colorizeImage sets white pixels to a secondary color
Posted: 2012-04-20T07:28:17-07:00
by charlie1234
If I apply $image->colorizeImage('#0000aa', 1) to a full color image, I have a blue tinted image that retains some of the original colors - cool, as expected.
If I first convert to grayscale via $image->modulateImage(100,0,100) and then apply the colorizeImage(), I get a nearly-perfect blue tinted image without any other colors, except for a minor yellow hue anywhere there was a #ffffff pixel. This is much more apparent when an image has a white background.
See the attached example. Is there any way to recolor an image and "force" a particular palette or color range?
Re: colorizeImage sets white pixels to a secondary color
Posted: 2012-04-20T07:51:26-07:00
by charlie1234
This is what I'm trying to ultimately achieve:
Re: colorizeImage sets white pixels to a secondary color
Posted: 2012-04-20T09:46:40-07:00
by fmw42
try convert to grayscale, then +level-colors blue,white. Change blue to whatever shade works best. You will have to overlay your black border again.
Re: colorizeImage sets white pixels to a secondary color
Posted: 2012-04-20T10:01:49-07:00
by charlie1234
The black border is just to show a background, i.e. that this has a white bg.
Can you describe the +level-colors blue, white? Is this syntax from the command line? I'm looking to achieve this within Imagick if possible, or if it must be on the command line do you know of a method to get the output directly without saving and printing a file?
Re: colorizeImage sets white pixels to a secondary color
Posted: 2012-04-20T10:18:32-07:00
by fmw42
It is a commandline option. My only reference to Imagick is
http://php.net/manual/en/book.imagick.php and I do not see it there. But that does not surprise me as Imagick is not well maintained and not kept up to data with Imagemagick options.
You can however, still use PHP exec() to do this step. It allows you to put IM command lines into the exec function to process them.
see
http://www.rubblewebs.co.uk/index.php
Re: colorizeImage sets white pixels to a secondary color
Posted: 2012-04-20T13:52:17-07:00
by charlie1234
Thanks for your help! This achieves
exactly what I am looking for (pretty much the image from my 2nd post above, which was done in Photoshop using a blue opaque layer with 'color' blending mode on top of a grayscale layer):
Code: Select all
$output = shell_exec('convert image.jpg -colorspace gray +level-colors "#0000aa",white -');
header("Content-Type: image/png");
print $output;