DrawImage changes to higher BitDepth
DrawImage changes to higher BitDepth
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!
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!
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: DrawImage changes to higher BitDepth
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.
You can also reduce your image to 255 colours.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: DrawImage changes to higher BitDepth
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.
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
@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.
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
@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.
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: DrawImage changes to higher BitDepth
So, is your input image paletted? If so, have you tried SetImageStorageClass() before writing?
snibgo's IM pages: im.snibgo.com
Re: DrawImage changes to higher BitDepth
@snibgo,
my input image is just grey-scale image.
I have not tried SetImageStorageClass() before writing.
my input image is just grey-scale image.
I have not tried SetImageStorageClass() before writing.
Re: DrawImage changes to higher BitDepth
As others said, you need to turn off antialiasing.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: DrawImage changes to higher BitDepth
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).
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: DrawImage changes to higher BitDepth
If you are using PHP, see http://phpimagick.com/ImagickDraw/setStrokeAntialias
snibgo's IM pages: im.snibgo.com