This question has been asked previously, but the approved answers do not work for me:
Prevent ImageMagick converting to grayscale
ImageMagick: convert keeps changing the colorspace to Gray. How to preserve sRGB colorspace?
Example image:
convert.exe logo: -type grayscalealpha png32:-|convert - -define png:color-type=6 png32:-|identify -verbose -
The only way to force what I want is to draw a color somewhere in the visible area. This accomplishes what I'm looking to do:
convert.exe logo: -type grayscalealpha png32:-|convert - -fill #11000000 -draw "rectangle 0,0 0,0" -|identify -verbose -
However, I'd prefer not altering the image. I've tried the above on the following builds on Win7:
ImageMagick 7.0.3-1 Q16 x64 2016-09-20
ImageMagick 6.9.0-10 Q16 x64 2015-02-28
EDIT: Just realized I'm drawing a clear pixel on top, so the image shouldn't change, yet it still works. Still feels like a hack though.
Updates:
After working on this some more hours, I realize my question wasn't clear because I wasn't clear on how PNGs are stored.
Problem: When ImageMagick is given an image with only gray colors (R=G=B), it will store the image, I think, with only one channel (gray).
I say "I think" because identify prints out type as "GrayscaleAlpha" and only lists a "Gray" and "Alpha" channel. The output of the second command will list type as "PaletteAlpha" and list Red, Green, Blue and Alpha. However, the property "png:IHDR.color-type" is 6 for both. So I think I may be misunderstanding the meaning of "Type" and "Base Type" used by ImageMagick.
(Also, ImageMagick V6 and V7 seem to have different behaviors with this. For example, v6 lists alpha channel as 1-bit, even though it is 8-bit.)