I had the exact same problem, and after much googling and reading of the ImageMagick documentation, this is what I've found.
To make the make the black pixels of an image transparent and keep the white pixels as they are, run this command:
Code: Select all
convert source.png -alpha copy -fx '#fff' result.png
To instead make the white pixels transparent and keep the black as they are, use:
Code: Select all
convert source.png -alpha copy -channel alpha -negate +channel -fx '#000' result.png
Let's explain that last command a bit more thoroughly:
- – Is the ImageMagic command (one of several)
- – The greyscale source image.
- – Copy contents of the previous file into the alpha channel.
- – Specify that following operators only should affect the alpha channel.
- – Invert the alpha channel (will, because of the previous not affect any other part of the image).
- – Specify that following operators only should should affect the color channels, and no longer modify the alpha channel. (This is the default, and therefore we need not provide it in the first, simpler example.)
- – Replace color channel contents with black pixels. (Because of the alpha channel will not be affected).
It is quite important to include that final
option, otherwise all semi-transparent pixels in generated image will retain colors. (Since these pixels are half-transparent, it might not be obvious, but the end result is not what one expect.)
I found the list of ImageMagick options quite useful:
http://www.imagemagick.org/script/comma ... ptions.php