How can save a grayscale image

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

How can save a grayscale image

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

Re: How can save a grayscale image

Post by snibgo »

It's just a warning. If the command does what you want, don't worry about it.
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: How can save a grayscale image

Post by fmw42 »

I also get this warning often. But it make my output image just fine.
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

Re: How can save a grayscale image

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can save a grayscale image

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

Re: How can save a grayscale image

Post 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.
snibgo's IM pages: im.snibgo.com
wizard29
Posts: 58
Joined: 2014-03-21T00:40:16-07:00
Authentication code: 6789
Location: Russia, Saint Petersburg
Contact:

Re: How can save a grayscale image

Post 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);

Post Reply