rendering antialiased text - variable size, transparency

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
imagerakete

rendering antialiased text - variable size, transparency

Post by imagerakete »

hey there,

i'm new to imagemagick and can't figure out how to achieve the following effect. maybe somebody can point me in the right direction!

i need to render text onto a transparent background. it needs to be antialised, and the size of the image should be determined by the content, rather than being fixed with something like -size 100x200. I also need to stroke the text with a white outline of 3-4 pixels.

i can get most of these effects happening, but not all at the same time! any ideas out there?

thanks in advance.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: rendering antialiased text - variable size, transparency

Post by fmw42 »

if you post your command line someone ought to be able to point out any problems.

When using label: (or caption:) you don't need to specify size http://www.imagemagick.org/Usage/text/#label

Use -background none to get a transparent background

Draw a white stroke color and a dark fill color to get the outline you want. You can specify the strokewidth to make it 3-4 pixels wide.
imagerakete

Re: rendering antialiased text - variable size, transparency

Post by imagerakete »

@fmw42 thanks for the input!

i guess my problem is that i don't know how to apply a stroke when label: ist set. here's the command that draws against a transparent bg *without* a stroke:

convert -background none -geometry +0+0 -fill \#bf0961 -pointsize 24 label:'Moo cow goes for a walk' -set label '' moo.png

and here's a command which does apply a stroke (mind the osx font location):

convert -size 320x100 xc:none -font /Library/Fonts/Arial.ttf -pointsize 24 -fill \#bf0961 -stroke white -strokewidth 6 -annotate +25+64.5 'Cow talk' -stroke none -annotate +25+65 'Cow talk' moo.png

problem with that is, i need a dynamic canvas size.

any ideas? i've tried out loads of combinations without cracking it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: rendering antialiased text - variable size, transparency

Post by fmw42 »

what I have done often is use label first to get an image, then get its size, then go back and use annotate to redo it by creating a canvas of the same size and then using stroke and anything else more sophisticated than is allowed by label.

See my texteffects script at http://www.fmwconcepts.com/imagemagick/index.html
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: rendering antialiased text - variable size, transparency

Post by anthony »

I explain label for size then use annotate technique in detail in IM examples
http://www.imagemagick.org/Usage/text/#size

Look at the 'Get Wet!' example.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
imagerakete

Re: rendering antialiased text - variable size, transparency

Post by imagerakete »

hey anthony,

thanks for pointing me at detailed information. i'm just trying to get to grips with the concepts involved, but running the get wet example produces the following error:

convert: unable to open image `tile_water.jpg': No such file or directory.

i pasted the command as is, using ImageMagick 6.4.1 08/05/08 Q16 on OSX.

any ideas what i'm doing wrong here? i'm finding it a bit difficult to get a grip on the syntax.

cheers!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: rendering antialiased text - variable size, transparency

Post by anthony »

The images used as starting points in examples can be found in the IM Examples Images Directory
http://www.imagemagick.org/Usage/images/

OR you can just prefix the image with the URL of the Examples so IM knows to download it from the web site.

For that example...

Code: Select all

 convert -font Ravie -pointsize 72  label:'Get Wet!' -border 10 \
          -tile http://www.imagemagick.org/Usage/text/tile_aqua.jpg   -draw "color 0,0 reset"  \
          -tile http://www.imagemagick.org/Usage/text/tile_water.jpg -gravity center -annotate +0+0 'Get Wet!' \
          autosize_wet.jpg
You may also need to get the Ravie font (see top level page)

But it is better for you to just get it once yourself.

Code: Select all

  convert http://www.imagemagick.org/Usage/text/tile_water.jpg tile_water.jpg
  convert http://www.imagemagick.org/Usage/text/tile_aqua.jpg ile_aqua.jpg
This is actually equivelent to using 'wget' available on most systems)


Basically download the image, or substitute your own, as detailed on the top level page about source images and fonts.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply