Page 1 of 1

DrawImage changes to higher BitDepth

Posted: 2017-01-10T00:01:36-07:00
by cuongvn08
My ImageMagick version in Linux is 6.7.7-10
I used the function drawImage() to add some circles into the 8-bit bmp.
However, the problem is after adding some circles, bitdepth of image became 24-bit.
Hopefully, I would like to keep the same bitdepth as the original image.

Is this a bug of ImageMagick or its real design?
Is there any suggestion to keep the same bitdepth?

Thanks so much!

Re: DrawImage changes to higher BitDepth

Posted: 2017-01-10T00:35:48-07:00
by snibgo
Your drawing may be aliased, in which case the boundary of areas and lines "merge" with the background, creating many new colours. You can prevent this with anti-aliasing.

You can also reduce your image to 255 colours.

Re: DrawImage changes to higher BitDepth

Posted: 2017-01-10T00:46:13-07:00
by fmw42
What format was the output? If PNG, then you can do PNG8:output.png to keep 8-bit color per image. With other formats add -type palette before the output. If snibgo is correct, you can add +antialising to keep from introducing new colors. Or use -type palette before saving to force it to 8-bit per image.

IM 6.7.7.10, is very old (about 200 version old) and was during a time when IM colorspace was changing. You might consider upgrading, if you can depending upon your OS.

Re: DrawImage changes to higher BitDepth

Posted: 2017-01-10T00:53:23-07:00
by cuongvn08
@fmw42, my output image is still bmp.
My application was written in php.
Code is simply like belows:

$img = new Imagick($image_input_8bit_bmp)

$draw = new ImagickDraw();
$draw->setStrokeOpacity(1);

$img->drawImage(draw);
$img->writeImage(image_output);


Finally, image_output is 24-bit bmp.
Is there any suggestion here to keep original bitdepth? Thanks.

Re: DrawImage changes to higher BitDepth

Posted: 2017-01-10T01:03:02-07:00
by snibgo
What are you drawing?

Re: DrawImage changes to higher BitDepth

Posted: 2017-01-10T01:15:23-07:00
by cuongvn08
@snibgo
I am going to add some circles but I disabled all these codes. Because I want to see the effect of ImagickDraw.
Even I just created an object of ImagickDraw and did not add anything, bitdepth of image_output was changed to 24.
My full code here:

$img = new Imagick($image_input_8bit_bmp)

$draw = new ImagickDraw();
$draw->setStrokeOpacity(1);

/*
for ($i=0; $i < count($array); $i++)
{
$draw->circle($array[$i][0], $array[$i][1], $array[$i][2]);
}
*/

$img->drawImage(draw);
$img->writeImage(image_output);

Of course, if I disable $img->drawImage(draw), bitdepth of image_output is still 8-bit.
That's why I confused the problem may be drawImage() and ImagickDraw. And this is a bug of ImageMagick.

Re: DrawImage changes to higher BitDepth

Posted: 2017-01-10T01:25:05-07:00
by snibgo
So, is your input image paletted? If so, have you tried SetImageStorageClass() before writing?

Re: DrawImage changes to higher BitDepth

Posted: 2017-01-10T01:32:28-07:00
by cuongvn08
@snibgo,
my input image is just grey-scale image.
I have not tried SetImageStorageClass() before writing.

Re: DrawImage changes to higher BitDepth

Posted: 2017-01-10T11:55:59-07:00
by glennrp
As others said, you need to turn off antialiasing.

Re: DrawImage changes to higher BitDepth

Posted: 2017-01-10T12:08:04-07:00
by fmw42
If you add color to a grayscale image, it will automatically increase the bit depth from 8-bits per image to 24-bits color per image (3 channels of 8-bits), unless you force the result to -type palette (8-bits color per image).

Re: DrawImage changes to higher BitDepth

Posted: 2017-01-10T16:55:58-07:00
by cuongvn08
glennrp wrote:
2017-01-10T11:55:59-07:00
As others said, you need to turn off antialiasing.
Could you please show me how can I turn off anti-aliasing?
And what is the effect of anti-aliasing here?
Thank you.

Re: DrawImage changes to higher BitDepth

Posted: 2017-01-10T18:55:28-07:00
by snibgo