Page 1 of 1

How can save a grayscale image

Posted: 2015-02-18T02:41:52-07:00
by wizard29
Hello, everyone.

I need to save an image that contains only semi-transparent greyscale pixel into PNG format.
The image is created as sRGB image with alpha channel. I attach some RGB ICC color profile to the image.

When I start to save the image I catch an exception that looks like:
"profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `C:/tmp1/out/Untitled-1.png' @ warning/png.c/MagickPNGWarningHandler/1656"

In case of the JPEG file format everything works fine and output file has an embedded ICC profile as I want.

How can I save an image in RGB color space with an RGB ICC profile in this case?

I use IM 6.9.0-7 and Magick++.

Re: How can save a grayscale image

Posted: 2015-02-18T13:04:25-07:00
by snibgo
It's just a warning. If the command does what you want, don't worry about it.

Re: How can save a grayscale image

Posted: 2015-02-18T13:42:32-07:00
by fmw42
I also get this warning often. But it make my output image just fine.

Re: How can save a grayscale image

Posted: 2015-02-18T23:16:20-07:00
by wizard29
I want to save an image with an embedded ICC profile. But in this case I cann't do this. PNG encoder builds a palette instead of saves an image as I want in RGB color space. Despite the RGB color space is installed to the source image before to save. Other encoders don't do this. How can I solve the problem?

Re: How can save a grayscale image

Posted: 2015-02-19T00:13:42-07:00
by fmw42
I do not think IM will create an RGB 24-bit PNG image for grayscale. It will always be type grayscale or palette. If you need an .icc profile for grayscale, there are some grayscale profiles, but I do not know if they are sRGB or more linear. TIF may support the sRGB.icc profile with the grayscale image and not complain. And you may be able to use -type truecolor to make it RGB. I have not tested that. I do not think that works for PNG. The PNG developer will need to comment.

Re: How can save a grayscale image

Posted: 2015-02-19T00:39:45-07:00
by snibgo
At the command line, prefix PNG24: makes a 3*8 bit file.

Code: Select all

f:\web\im>%IM%convert -size 10x10 gradient: PNG24:x.png

f:\web\im>dumppng /ix.png
Read OK                width 10, height 10, pixdepth 24, palnum 0, topdown FALSE
width 10, height 10
Embedding sRGB.icc profile in a greyscale PNG works fine, for me, in a command.

Re: How can save a grayscale image

Posted: 2015-02-19T01:37:55-07:00
by wizard29
Thank you for direction of research!

I solve the issue for the PNG encoder. Set special PNG encoder settings helps:

Code: Select all


// point to encoder's bit depth
image.defineValue("png", "bit-depth", "8");
// point to encoder's color space type
image.defineValue("png", "color-type", "6");

Didn't work for the PNG encoder if I do this:

Code: Select all


image.colorSpace(Magick::sRGBColorspace);
image.type(Magick::TrueColorMatteType);