1-bit grayscale to TrueColor not working

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
groupboard
Posts: 2
Joined: 2016-12-07T11:26:25-07:00
Authentication code: 1151

1-bit grayscale to TrueColor not working

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

Re: 1-bit grayscale to TrueColor not working

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: 1-bit grayscale to TrueColor not working

Post 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.
groupboard
Posts: 2
Joined: 2016-12-07T11:26:25-07:00
Authentication code: 1151

Re: 1-bit grayscale to TrueColor not working

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

Re: 1-bit grayscale to TrueColor not working

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply