Page 1 of 1

1-bit grayscale to TrueColor not working

Posted: 2016-12-07T11:30:39-07:00
by groupboard
I have a 1-bit grayscale image that I'm trying to convert to 24-bit TrueColor png (no alpha). However imagemagick seems to always create an all-black image. Here is the command:

convert -background white -alpha off -type TrueColor -depth 8 working.png PNG24:test.png

(originally I didn't have the " -background white -alpha off" options, but that produced the same result).

Original image:

http://www.groupboard.com/working.png

Converted image:

http://www.groupboard.com/bad.png

This is with v6.7.2-7, but I also tried with the latest version and it has the same problem.

Re: 1-bit grayscale to TrueColor not working

Posted: 2016-12-07T12:19:10-07:00
by snibgo
Working.png is 8 bits, not 1 bit. All the pixels are black, with varying transparency.

PNG24: is sufficient to give it 3 channels, in v6.9.5-3.

Re: 1-bit grayscale to TrueColor not working

Posted: 2016-12-07T12:22:13-07:00
by glennrp
Your original image isn't a one-bit grayscale image; it's a 16-bit Gray-alpha image in which the 8-bit Gray component is always black and the 8-bit alpha component carries the actual image of the text. You can make a visible image by doing

Code: Select all

magick working.png -background white -flatten png24:flattened.png
Use "convert" instead of "magick" with older versions of ImageMagick.

Re: 1-bit grayscale to TrueColor not working

Posted: 2016-12-07T17:36:13-07:00
by groupboard
Ok, thanks - that works. Some of the images I was having problems with were 1-bit grayscale, but that particular one is 8-bit.

The problem seems to be the TrueColor that is screwing things up in this particular case. Should "-type TrueColor -depth 8" not do the same thing as putting png24: on the dest image? I don't understand

Re: 1-bit grayscale to TrueColor not working

Posted: 2016-12-08T07:56:24-07:00
by snibgo
"-type XXX" is really just a hint to file encoders (the software that writes output files). The different encoders (for PNG, TIFF, JPG etc) use these hints in slightly different ways when deciding how many channels, and how many bits/channel, to write in the file.

"PNG24:" instructs the PNG encoder to use exactly 3 channels, with exactly 8 bits in each.