Semi-Transparent Text on Transparent Background

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
jgrauman
Posts: 15
Joined: 2010-06-15T23:42:05-07:00
Authentication code: 8675308

Semi-Transparent Text on Transparent Background

Post by jgrauman »

Hello all,

I'm trying to figure out how to create text with a completely transparent background, where the text itself has some transparency as well. I'd like text that is 20% transparent on a completely transparent background. The following achieves what I want (minus the transparent text). Can someone help me figure out how to make the text a certain amount transparent? Thanks!

convert -channel RGBA -gravity center -size 35x17 xc:none -font Arial-Regular -pointsize 13 -fill black -annotate +0+0 Text -background transparent -flatten out.png

Josh
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Semi-Transparent Text on Transparent Background

Post by snibgo »

Red text with 80% opacity (Windows script):

Code: Select all

convert ^
  -size 35x17 xc:none ^
  -gravity Center ^
  -fill rgba(255,0,0,0.80) -font c:\windows\fonts\arial.ttf -pointsize 13 -annotate +0+0 "Text" ^
  out.png
snibgo's IM pages: im.snibgo.com
jgrauman
Posts: 15
Joined: 2010-06-15T23:42:05-07:00
Authentication code: 8675308

Re: Semi-Transparent Text on Transparent Background

Post by jgrauman »

Thanks! Works like a charm.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Semi-Transparent Text on Transparent Background

Post by snibgo »

Tut tut, what was I thinking of? That script should be:

Code: Select all

convert ^
  -size 35x17 xc:none ^
  -gravity Center ^
  -fill rgba(100%%,0,0,0.80) -font c:\windows\fonts\arial.ttf -pointsize 13 -annotate +0+0 "Text" ^
  out.png
which uses the more portable 100%. (Don't double the % for Unix.) Note that alpha in rgba() ranges from 0 to 1. IM will silently ignore a %-sign in the alpha.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Semi-Transparent Text on Transparent Background

Post by anthony »

Another alternative is just annotate 'red' text on your transparent background.

Then use -channel A -evaluate multiply 0.8 +channel to make everything at least slightly transparent.

This will work with anything text, images etc. And using a color name like 'red' make things a lot easier to edit later.

See IM examples, Transform Images Evaluate Multiply
http://www.imagemagick.org/Usage/transf ... e_multiply
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply