Transparency & color channel advice

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
ian313665

Transparency & color channel advice

Post by ian313665 »

I'm creating a texture font library to help me with some graphics rendering.

At the moment, I'm using this command which is used in a build script to loop over all the characters I want to generate:

Code: Select all

convert -colorspace RGB -background black -fill white -pointsize 50 label:A font.65.tiff
I want to adjust this command so I put the letter 'A' into the alpha channel of the tiff file and I simply want a white colour fill in the RGB channels.

If anyone can offer any advice on how to do this, it would be much appreciated.

Thanks.
Last edited by ian313665 on 2009-11-07T15:34:31-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Transparency & color channel advice

Post by fmw42 »

convert \( -background black -fill white -pointsize 50 label:A \) \
\( +clone -threshold -1 \) \
-alpha off +swap -compose copy_opacity -composite font.65.tifffont.65.tiff

First line creates the letter A as b/w image for use as the alpha channel. The second line thresholds the first to be completely white. The third line puts the letter A image into the alpha channel of the white image.
ian313665

Re: Transparency & color channel advice

Post by ian313665 »

I tried the command and although it 'did' work, it didn't have a nice feathered edge in the alpha channel. I think this bug however, because if I repeat the same command but use TGA instead of TIFF, the result is perfect.

Here is the result I got from the command:

http://www.asura.co.uk/font.65.tiff (TIFF format)
http://www.asura.co.uk/font.65.tga (TGA format)

I've had similar problems with TIFF in the past (on Mac OSX) so I'll update the bug report I submitted a few weeks ago.

Thanks for the help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Transparency & color channel advice

Post by fmw42 »

-colorspace RGB will not help. You have not specified any color for the text, so it will be black and white (binary image).

Use

identify -verbose yourimage.tif

to see that it is colorspace RGB, but a bilevel type with 1-bit per channel grayscale and 1-bit per alpha

The example I provided for you to put the character A in the alpha channel works as you asked to make a white character on a transparent (white) background if you use PNG.

for tiff try this

convert \( -background black -fill white -pointsize 50 label:A -alpha off \) \
\( +clone -threshold -1 \) \
-alpha off +swap -compose copy_opacity -composite -depth 8 font.65.tiff

or as png (without the -depth 8)

convert \( -background black -fill white -pointsize 50 label:A -alpha off \) \
\( +clone -threshold -1 \) \
-alpha off +swap -compose copy_opacity -composite font.65.png

Tiff is strange and has a lot of special arguments and different interpretations. Don't recommend using it.

see http://www.imagemagick.org/Usage/formats/#tiff

If you don't care what the transparent background color is, that is if it can be black rather than white, then this is simpler:

convert -background black -fill white -pointsize 50 label:A -alpha off \
-density 8 -alpha copy font.65.tiff
Post Reply