Page 1 of 1

Transparency & color channel advice

Posted: 2009-11-07T14:18:47-07:00
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.

Re: Transparency & color channel advice

Posted: 2009-11-07T15:20:03-07:00
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.

Re: Transparency & color channel advice

Posted: 2009-11-08T04:50:06-07:00
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.

Re: Transparency & color channel advice

Posted: 2009-11-08T14:42:20-07:00
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