Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically convert RGB image to 1-bit Grayscale (b/w) bitmap image with PHP and ImageMagick
    primarykey
    data
    text
    <p>I'm trying to programmatically convert a bitmap RGB image to 1-bit Grayscale (b/w) bitmap image using PHP (version: 5.2.13) and ImageMagick (version: 6.7.8-7-Q16). The input image is bitmap and is generated by means of the ImageMagick function:</p> <pre><code>bool Imagick::setFormat ( string $format ) </code></pre> <p>where $format = 'bmp2'</p> <p>The following code used to work in the past (older version of ImageMagick... don't remember which one), but it's not working anymore in the current environment:</p> <pre><code>private function monochrome() { if (isset($this-&gt;image)) { try { // reduce image colors to 2 (black and white) $this-&gt;image-&gt;quantizeImage(2, Imagick::COLORSPACE_GRAY, 5, false, true); // reduce image depth to 1 bit per pixel $this-&gt;image-&gt;setImageDepth(1); $this-&gt;image-&gt;setImageChannelDepth(Imagick::CHANNEL_ALL, 1); // set image type to monochrome (2 colors: black and white only) $this-&gt;image-&gt;setImageType(Imagick::IMGTYPE_BILEVEL); } catch (ImagickException $ie) { throw $ie; } } else { throw new Exception("No image object"); } } </code></pre> <p>The problem is that the image produced is still in the RGB color space.</p> <p>I also tried:</p> <pre><code>$this-&gt;image-&gt;setImageColorSpace(Imagick::COLORSPACE_GRAY); </code></pre> <p>but the result does not change.</p> <p>My goal is to generate the smallest possible, black and white, bitmap image for a signature capture application. I know there are better image formats than bitmap, but the generated image has to be compatible with the old Access 97. That is why 'bmp2' is the choice for the image format.</p> <p>Any ideas? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload