Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP ImageMagick setColorspace not working [duplicate]

I'm trying to convert an image to black and white by altering the colorspace with this code:

$im = new Imagick('image.png');
$im->setImageColorspace(Imagick::COLORSPACE_GRAY);
$im->writeImage('out.png');

However after this code, there is no visible change to the image (out.png and image.png look indistinguishable). Any thoughts on why this might be? Is this the proper method to convert and image to B&W? Are there any other methods?

I've also tried setColorspace(Imagick::COLORSPACE_GRAY); with the same results.

Here's the software I'm using:

ImageMagick 6.6.9-7
PHP 5.3.10-1ubuntu3.1
Server version: Apache/2.2.22 (Ubuntu)

Edit: Some extra info

I've also tried converting to other colorspaces (specifically CMY and CMYK) and noticed no visual difference then either.

like image 426
gregghz Avatar asked Feb 11 '26 01:02

gregghz


1 Answers

As an alternative, you can try $im->modulateImage(100,0,100); instead of setImageColorspace()

Hope this helps!

like image 148
Justin T. Avatar answered Feb 13 '26 15:02

Justin T.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!