Why is IM converting image to Grayscale

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
unifant
Posts: 9
Joined: 2010-11-04T03:55:43-07:00
Authentication code: 8675308

Why is IM converting image to Grayscale

Post by unifant »

Hi there, this is a little bit confused.

I have a 24 PNG icon-image with white and transparence and want to fill the colored part with a different color like this:

Code: Select all

convert src.png -fill rgba(0,0,0, 0.0) -colorize 100% target.png 
or

Code: Select all

convert src.png -fill rgba(156,222,250, 0.0) -colorize 100% target.png
When i take a color like 0,0,0 (black) then IM saves the image as grayscale image and when i take an other color like 156,222,250 (a light-blue color) then IM makes an indexed grafik of this without any antialiasing.

What's that? How can i solve this problem? I want to get a 24PNG graphic with antialiasing as result.

Thanks a lot!

I'm Using :
ImageMagick 6.7.3-2 2011-10-13 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Why is IM converting image to Grayscale

Post by fmw42 »

You need to put quotes around your rgb and rgba color definitions. This is especially the case when you put spaces in the definitions. It is always a good idea to remove spaces in color definitions.

convert src.png -fill "rgba(156,222,250,0.0)" -colorize 100% target.png
unifant
Posts: 9
Joined: 2010-11-04T03:55:43-07:00
Authentication code: 8675308

Re: Why is IM converting image to Grayscale

Post by unifant »

Thanks for your reply.

Now i have:

Code: Select all

convert src.png -fill "rgba(0,0,0,0.0)" -colorize 100% target.png
but it is still the same problem.

An other idea?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Why is IM converting image to Grayscale

Post by fmw42 »

unifant wrote:Thanks for your reply.

Now i have:

Code: Select all

convert src.png -fill "rgba(0,0,0,0.0)" -colorize 100% target.png
but it is still the same problem.

An other idea?
If you want to fill the other colors, then -colorize is not correct. It fills the whole image with that color.

You need to use -fill ... -opaque or -fill +opaque

What color is in the image you want to change and to what color. Here is an example to change white to yellow

convert logo: -fuzz 1% -fill yellow -opaque white logo_tmp1.png

Here is the same example to change everything but white to yellow

convert logo: -fuzz 1% -fill yellow +opaque white logo_tmp1.png

The -fuzz XX% allows for the white to be not pure white, so it gets near colors.


See http://www.imagemagick.org/Usage/color_basics/#replace
unifant
Posts: 9
Joined: 2010-11-04T03:55:43-07:00
Authentication code: 8675308

Re: Why is IM converting image to Grayscale

Post by unifant »

Hi,

i don't have a problem with coloring the image. This part works.
I have an icon inside this graphic in white color and the other part is transparent.
This way i color every part of the image, which is not transparent.

My problem is that IM converts the target image to Grayscale-Image when it is black or grey color and makes an indexed image, when it has an other color. The source image is PNG 24.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Why is IM converting image to Grayscale

Post by fmw42 »

I think you need to post a link to your image, so we can see what is happening. And please explain how you want this image changed.
unifant
Posts: 9
Joined: 2010-11-04T03:55:43-07:00
Authentication code: 8675308

Re: Why is IM converting image to Grayscale

Post by unifant »

This one is the original image
Image
http://www.fotoporto.de/imagemagick/search.png
identify -verbose shows this

Code: Select all

Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 17x17+0+0
Resolution: 72x72
Print size: 0.236111x0.236111
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
...

This one comes out, when i use rgba(68,68,68,0.0)
Image
http://www.fotoporto.de/imagemagick/search_gray.png
identify -verbose shows this

Code: Select all

Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 17x17+0+0
Resolution: 72x72
Print size: 0.236111x0.236111
Units: Undefined
Type: GrayscaleMatte
Base type: GrayscaleMatte
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
...
This one is a grayscaled graphic, when i open it in Photoshop. In Browser it looks right.

And finally this one comes out, when i use rgba(156,222,250,0.0)
Image
http://www.fotoporto.de/imagemagick/sea ... htblue.png

identify -verbose shows this

Code: Select all

Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 17x17+0+0
Resolution: 72x72
Print size: 0.236111x0.236111
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
...  
This one is an indexed graphic with no antialiasing, when i open it in Photoshop. In Browser it looks right.
It looks like this
Image
http://www.fotoporto.de/imagemagick/sea ... toshop.png


Both should be PNG 24 RGB not grayscaled and not indexed.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Why is IM converting image to Grayscale

Post by fmw42 »

If you do not have more than 256 colors, IM will default to palette and if transparency is present then palettematte. That is what I get for:


convert 1search.png -fill "rgba(156,222,250,0.0)" -colorize 100% 1search_blue.png

identify -verbose 1search_blue.png
Image: 1search_blue.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 17x17+0+0
Resolution: 72x72
Print size: 0.236111x0.236111
Units: Undefined
Type: PaletteMatte
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 8-bit

I do not get grayscale, except when you specify a gray set of colors.

What version of IM are you using and what platform. The above was using IM 6.7.6.5 Q16 Mac OSX Snow Leopard

Usually you can force it to 32bit color by

convert 1search.png -fill "rgba(156,222,250,0.0)" -colorize 100% PNG32:1search_blue2.png

But that does not seem to work.

This would be a question for the PNG developer, glennrp. He will likely get online sometime later and he can give a better answer.
unifant
Posts: 9
Joined: 2010-11-04T03:55:43-07:00
Authentication code: 8675308

Re: Why is IM converting image to Grayscale

Post by unifant »

Thanks,

i tried various thinks like
-depth 8
PNG24:target.png
-colorspace RGB

but nothing helped.

I'm using
I'm Using :
ImageMagick 6.7.3-2 2011-10-13 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
on Mac OSX Lion
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Why is IM converting image to Grayscale

Post by fmw42 »

colorspace and depth will not help. PNG24 will remove the transparency. you would need PNG32, but I tried that and it did not force to 32 bit truecolor. I also tried by adding -type truecolormatte and also -define png:color-type=6. But they did not help either.

see
http://www.imagemagick.org/Usage/formats/#png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Why is IM converting image to Grayscale

Post by anthony »

By default IM will try to use the BEST image file format to hold the image.
For example palette images, greyscale images, or even 8 bit images if all colors are exactly 8 bit colors.

The -type option is ment to tell coders exactly what type of image it should produce. that is override that automatic handling.

PNG images goes further and provides defines to specify the exact PNG sub-format to use.

See IM Examples, PNG Images, Ouput settings
http://www.imagemagick.org/Usage/formats/#png_formats
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Why is IM converting image to Grayscale

Post by fmw42 »

anthony wrote:By default IM will try to use the BEST image file format to hold the image.
For example palette images, greyscale images, or even 8 bit images if all colors are exactly 8 bit colors.

The -type option is ment to tell coders exactly what type of image it should produce. that is override that automatic handling.

PNG images goes further and provides defines to specify the exact PNG sub-format to use.

See IM Examples, PNG Images, Ouput settings
http://www.imagemagick.org/Usage/formats/#png_formats
I tried all that and it did not seem to work for me. Perhaps Glenn can clarify or verify.
unifant
Posts: 9
Joined: 2010-11-04T03:55:43-07:00
Authentication code: 8675308

Re: Why is IM converting image to Grayscale

Post by unifant »

Hi,

saving the file as PNG32 seems to work now. No grayscale and not indexed.

Thanks a lot.
Post Reply