How To Create a Monotone Image?...

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
ok200

How To Create a Monotone Image?...

Post by ok200 »

Image

Hi Everyone,

I am trying to create the effect as showed in the attached example.

In photoshop this effect works like this:
source image RGB
image mode = grayscale
image mode = duotone / monotone
All gray and black tones are replaced by the color you choose.

Anyone?

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How To Create a Monotone Image?...

Post by fmw42 »

In command line you would use +level-color blue-white

convert grayscaleimage +level-color blue-white result

see http://www.imagemagick.org/Usage/color/#level-colors

But I don't know if Imagick can do +level-color? see http://us3.php.net/manual/en/function.i ... limage.php

You could also try -tint or create your own color gradient and apply it via -clut or duotone effect

see http://www.imagemagick.org/Usage/color/#duotone and http://www.imagemagick.org/Usage/color/#clut
hampleman

Re: How To Create a Monotone Image?...

Post by hampleman »

As far as I can see, PHP-Imagick can't do level-colors. The Imagick::levelImage fmw42 revers to can only adjust the levels of an image: move or stretch the histogram.
Better try this:

Code: Select all

<?php
$imgUrl = 'image.jpg';
$image = new Imagick($imgUrl);
//make Grayscale image
$image->quantizeImage (256, imagick::COLORSPACE_GRAY, 10, false, false);
//make monotone blue
$image->setImageColorspace(imagick::COLORSPACE_RGB);
$image->colorizeImage ('#1200FF',1);
header('content-type: image/jpg');
echo $image;
?>
 
I Don't know what the third argument, int $treedepth of quantizeImage means; 10 or 10000 gives the same result, so never mind. See http://nl2.php.net/manual/en/function.i ... eimage.php

Also $image->setImageColorspace(imagick::COLORSPACE_GRAY) does not work on my local Imagick. Looks like some sort of bug. On my testing server it does work, but it generates a grayscale image that has lot more than 256 colors. That's why I use imagick::quantizeImage.

(another side track) Testing above script I discovered that $image->quantizeImage (256, imagick::COLORSPACE_GRAY, 10, false, false); does not affect the original image when it has less than 256 colors (and again it does work as expected on my remote server) ... did I discover a bug?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How To Create a Monotone Image?...

Post by fmw42 »

ok200

Re: How To Create a Monotone Image?...

Post by ok200 »

thanks everyone!
clut-image seems to do the best job.
Post Reply