DrawImage changes to higher BitDepth

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
cuongvn08
Posts: 6
Joined: 2017-01-09T23:50:54-07:00
Authentication code: 1151

DrawImage changes to higher BitDepth

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: DrawImage changes to higher BitDepth

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: DrawImage changes to higher BitDepth

Post 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.
cuongvn08
Posts: 6
Joined: 2017-01-09T23:50:54-07:00
Authentication code: 1151

Re: DrawImage changes to higher BitDepth

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: DrawImage changes to higher BitDepth

Post by snibgo »

What are you drawing?
snibgo's IM pages: im.snibgo.com
cuongvn08
Posts: 6
Joined: 2017-01-09T23:50:54-07:00
Authentication code: 1151

Re: DrawImage changes to higher BitDepth

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: DrawImage changes to higher BitDepth

Post by snibgo »

So, is your input image paletted? If so, have you tried SetImageStorageClass() before writing?
snibgo's IM pages: im.snibgo.com
cuongvn08
Posts: 6
Joined: 2017-01-09T23:50:54-07:00
Authentication code: 1151

Re: DrawImage changes to higher BitDepth

Post by cuongvn08 »

@snibgo,
my input image is just grey-scale image.
I have not tried SetImageStorageClass() before writing.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: DrawImage changes to higher BitDepth

Post by glennrp »

As others said, you need to turn off antialiasing.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: DrawImage changes to higher BitDepth

Post 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).
cuongvn08
Posts: 6
Joined: 2017-01-09T23:50:54-07:00
Authentication code: 1151

Re: DrawImage changes to higher BitDepth

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: DrawImage changes to higher BitDepth

Post by snibgo »

snibgo's IM pages: im.snibgo.com
Post Reply