Reputation: 85
My programming platform is:
My code:
$img = new Imagick($image_input_24bit_bmp);
$img->setimagedepth(8);
$img->writeImage($image_output);
Then image_output is still 24-bit bmp image.
The thing I would like is convert the 24-bit bmp image to the 8-bit bmp image. Thanks.
Upvotes: 3
Views: 1767
Reputation: 207345
You can force an 8-bit palettised BMP image (which is what I presume you mean) like this:
$im = new imagick('input.bmp');
$im->quantizeImage(256,Imagick::COLORSPACE_RGB,0,false,false);
$im->writeImage('result.bmp');
That will have a palette of 256 colours (each one 8-bit Red, plus 8-bit Green, plus 8-bit Blue), and each pixel will be represented by its index into that palette.
Upvotes: 1
Reputation: 3294
The setImageDepth
just isn't enough. You need to quanitize
the image.
Example:Test Script
$im = new imagick('stupid.png'); //an image of mine
$im->setImageFormat('PNG8');
$colors = min(255, $im->getImageColors());
$im->quantizeImage($colors, Imagick::COLORSPACE_RGB, 0, false, false );
$im->setImageDepth(8 /* bits */);
$im->writeImage('stupid8.png');
Upvotes: 1