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
Apply Color Map To PNG w/Alpha Channel
Re: Apply Color Map To PNG w/Alpha Channel
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.
- 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
Does the mymap.png file have any transparent colors in it?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Apply Color Map To PNG w/Alpha Channel
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
Drarakel-- thanks for the heads-up; I'll give it a try and see what happens.
Bryan
Re: Apply Color Map To PNG w/Alpha Channel
The "-type TrueColorMatte" option isn't working...
Bryan
Bryan
- 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
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.
-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.
Re: Apply Color Map To PNG w/Alpha Channel
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
=============================================
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
=============================================
- 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
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/
https://imagemagick.org/Usage/