Page 1 of 1
swapping a colour while maintaining alpha channel
Posted: 2011-07-28T07:02:02-07:00
by sam_anthony
Source image:
http://www.realtyhub.com.au/images/icon ... 000000.png
This image only has one colour, black.
The anti aliasing is done with pure black pixles which are semitransparent.
I want to swap the black with another colour, however when I do the semi transparent black is not changed.
Using command:
convert icons.png -fill red -opaque black out.png
Output image:
http://www.realtyhub.com.au/images/out.png
Need to use semi transparent anti aliasing as the image will be ontop of a item of unknown colour.
Thanks
ImageMagick 6.7.1-0 – Windows 7
Re: swapping a colour while maintaining alpha channel
Posted: 2011-07-28T09:31:37-07:00
by fmw42
try this
convert icons_000000.png -alpha off -fill red -opaque black -alpha on icons_000000_red.png
Re: swapping a colour while maintaining alpha channel
Posted: 2011-07-28T17:45:18-07:00
by anthony
As a FYI, what that suggestion does is 'disable alpha channel' so it is not seen, modify the image, then re-enable the preserved alpha.
Other techniques include using
+level-colors dodgerblue with the default channel setting (which does not include alpha). Or one of many other
Global Color Modification of the image.
Another suggestion is that as the image is a 'shape mask', then you can just extract the alpha, and then use it as a colored shape mask.
Code: Select all
convert icon.png -alpha extract -background seagreen -alpha shape result.png
See
http://www.imagemagick.org/Usage/masking/#shapes
Re: swapping a colour while maintaining alpha channel
Posted: 2011-07-28T17:48:39-07:00
by sam_anthony
Thanks for your help, what you suggested worked.
Re: swapping a colour while maintaining alpha channel
Posted: 2011-07-28T17:49:49-07:00
by fmw42
As Anthony points out, the reason your method did not work was all colors in a transparent image need to be specified with alpha values. So red must be, for example, rgb(255,0,0,1), and black must be rgb(0,0,0,1) where both are opaque. So rather than mess with this, as I was not sure what the result would be when not modifying partially transparent values, I chose simply to turn off the alpha channel so that one could avoid having to specify the alpha value for each color. Then turn the original alpha channel back on.
Sorry, at the time I wrote my earlier message, I was in a hurry to leave for an appointment, and thought I could get back to the explanation earlier.