Apply Color Map To PNG w/Alpha Channel

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
bcgreen24

Apply Color Map To PNG w/Alpha Channel

Post by bcgreen24 »

I'm using the following command to apply a color map to an image:

/usr/bin/convert ./uploads/logoshrunk.png +dither -map mymap.png ./uploads/logoindexed.png

It works just fine-- unless the PNG has an alpha channel. When this is the case, the transparent areas are rendered as black. Is this a bug, or am I doing something horribly wrong?

Thanks!
Bryan
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Apply Color Map To PNG w/Alpha Channel

Post by Drarakel »

It's a bug (at least if you have only simple binary transparency). Indexed PNGs can't handle transparency correctly at the moment. Meanwhile, add "-type TrueColorMatte" to your command - with that, a correct (PNG32) file should get written.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Apply Color Map To PNG w/Alpha Channel

Post by anthony »

Does the mymap.png file have any transparent colors in it?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
bcgreen24

Re: Apply Color Map To PNG w/Alpha Channel

Post by bcgreen24 »

Nope, the 'mymap.png' image that I'm using as a color map does not contain any transparency.

Drarakel-- thanks for the heads-up; I'll give it a try and see what happens.

Bryan
bcgreen24

Re: Apply Color Map To PNG w/Alpha Channel

Post by bcgreen24 »

The "-type TrueColorMatte" option isn't working...

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

Re: Apply Color Map To PNG w/Alpha Channel

Post by fmw42 »

Try adding

-colorspace rgba -matte

to your command and see if that helps. Put it right after your input image.

Also if your colormap does not have any transparent colors then you are mapping an image with transparency to one that does not, if I am not mistaken.

You can also try

convert image -alpha off -map colormap -alpha on result

that may turn off the transparent channel, do the mapping, and then turn your original alpha channel back on.

I am not really sure I know what you expect to happen with the transparent colors in your original image when you have a color map with no transparency. So I am not sure what really makes sense to suggest.
bcgreen24

Re: Apply Color Map To PNG w/Alpha Channel

Post by bcgreen24 »

Hmmm...I took the client's color map and added a transparent section to it-- still didn't work.

I'll try the suggestions above and see what happens..thank you all so much for your efforts. It is VERY much appreciated.

============================================
***UPDATE***
I don't know why it didn't work before, but I took the original color map and added a little transparent block to it, and now the color mapping is working exactly as I wanted it to in the first place. So there is no bug-- I just stupidly hadn't included a transparent section in the PNG I was using as a color map.

Thanks all!!!

Bryan
=============================================
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Apply Color Map To PNG w/Alpha Channel

Post by anthony »

Try using -quantize transparent which treels the color dither to ignore transparency in the image when assigning colors.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply