Page 1 of 1

PNG conversion forcing grayscale

Posted: 2014-03-19T09:43:14-07:00
by Lev
Hey all,

I'm having some very weird problems when trying to convert PNGs on ImageMagick 6.8.8-8 Q16 x64 on Windows 7.

If the PNG only has grays in it, and I do an identify -verbose on it, the image shows as being Colorspace: Gray, regardless of how I've saved it in Photoshop. However, if I open this file in photoshop, it opens and correctly recognises the file as being in sRGB.

However, if I then use ImageMagick to convert the PNG to anything, even another PNG, and then open that file in Photoshop, it now opens with a Gray colorspace.

This is the case even if I use convert file1.png -type TrueColorMatte -colorspace sRGB -set colorspace sRGB file2.png, which has every way I could think of to force it to maintain an sRGB colorspace.

This is a problem because I am using IM to convert PNGs to TIFs for printing, and the print software for our printers is unable to read gray tifs for some reason.

The only workaround we have right now is to include a colored pixel in the image at opacity 1%, which then stops IM from converting the image to Gray, but we are unable to enforce that with images coming in from external sources.

Am I doing something wrong or is it a bug in IM?

Re: PNG conversion forcing grayscale

Posted: 2014-03-19T10:42:47-07:00
by snibgo
Within IM, "colorspace:Gray" is really shorthand for "colorspace sRGB but all the pixels are gray".

When IM saves all-gray pixels as png, it will create a 1-channel png, unless you specify PNG24: or PNG48: etc.

I don't know of any way to force a gray image to have 3 channels in tiff.

Re: PNG conversion forcing grayscale

Posted: 2014-03-19T14:12:54-07:00
by fmw42
IM 6 actually has 3 channels even for grayscale. That is likely why it is labeled grayscale, so that IM knows all 3 channels are the same. IM 7 will only have one channel.

You may be able to modify the colorspace in the png or tif file using EXIFtool.

Re: PNG conversion forcing grayscale

Posted: 2014-03-20T06:43:58-07:00
by Lev
Cool, okay - thanks guys! Converting to PNG24: converted the alpha channel to 1 bit, which broke my alpha gradients, but PNG wasn't my end goal anyway so that's okay.

I actually found that, for my purposes, convert file1.png -type TrueColorMatte file2.tif does what I need! Still weird about the PNG stuff though

Re: PNG conversion forcing grayscale

Posted: 2014-03-20T07:10:38-07:00
by glennrp
Lev wrote:Cool, okay - thanks guys! Converting to PNG24: converted the alpha channel to 1 bit, which broke my alpha gradients
If you want to preserve full alpha, then use PNG32 instead of PNG24.