How do I create transparent text

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
kareed
Posts: 11
Joined: 2010-05-17T08:06:36-07:00
Authentication code: 8675308

How do I create transparent text

Post by kareed »

I am trying to create a file with a transparent background and transparent text. I would like to have the text white but have it be a tranparency of 35%. I have tried a lot of things and I can't seem to be able to get it to work. Below is where I am at. I am using label because I don't know what the final dimensions are going to be. Thanks for the help.

convert -background transparent -fill "rgb(255,255,255)" -gravity West -font arial.ttf'
-pointsize 20 label:"This is a test" -background transparent -flatten -trim +repage testFile.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How do I create transparent text

Post by snibgo »

As we are trimming, gravity is superfluous. With transparent black background, and opaque White letters, we can multply all alpha values by 0.35 to make the letters semi-transparent:

Code: Select all

convert -background transparent -fill White -font arial.ttf -pointsize 20 label:"This is a test" -channel alpha -evaluate multiply 0.35 -trim +repage testFile.png
An alternative, perhaps more elegant and quicker, is to specify the RGBA of the letters:

Code: Select all

convert -background transparent -fill rgba(255,255,255,0.35) -font arial.ttf -pointsize 20 label:"This is a test" -trim +repage testFile.png
Note that alpha is specified here as a fraction.
snibgo's IM pages: im.snibgo.com
Post Reply