PNG conversion forcing grayscale

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
Lev
Posts: 3
Joined: 2014-03-19T08:05:08-07:00
Authentication code: 6789

PNG conversion forcing grayscale

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

Re: PNG conversion forcing grayscale

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG conversion forcing grayscale

Post 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.
Lev
Posts: 3
Joined: 2014-03-19T08:05:08-07:00
Authentication code: 6789

Re: PNG conversion forcing grayscale

Post 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
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: PNG conversion forcing grayscale

Post 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.
Post Reply