avo has asked for the wisdom of the Perl Monks concerning the following question:

Good day monks, I would like to ask you ... how can I create an image using any of the available graphics modules which can render a font with an outline / border settings. For instance color, size. In most vector applications this is a standard option...

Thank you very much in advance.

Replies are listed 'Best First'.
Re: Draw Font Outline
by CountZero (Bishop) on Nov 19, 2007 at 11:13 UTC
    I am no graphic artist or font-guru, but a quick search on CPAN turned up: Font::TTF which seems to allow one to "hack" the TTF-type of fonts. Perhaps you can use this as a starting point?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Draw Font Outline (PS solution)
by almut (Canon) on Nov 19, 2007 at 14:50 UTC

    Not really a Perl solution, but maybe it helps...  Also, this is limited to PostScript fonts (well, not strictly, but with other font types, things would get much more involved).

    The real work is being done by the PostScript interpreter (gs in this case). Perl is just writing the PS commands to a temp file and then running the PS interpreter (which could of course be done equally well with a simple shell script — but as this is a Perl forum ... :)

    The example would produce a 1000x500 pixel PNG file showing the word "Perl" in big letters being rendered in a blue dotted outline.

    If you want to use any non-standard PS fonts, you have to include the respective .pfa or .pfb font files at the beginning of the PS code (where indicated). If you don't want PNG output, you can simply choose a different driver and specify it via -sDEVICE=... ("gs -h" for a list of available devices).

    #!/usr/bin/perl my $tmpfile = "demo.ps"; my $outfile = "demo.png"; open my $ps, ">", $tmpfile or die "Cannot create temp file '$tmpfile': + $!"; print $ps <<'EOF'; %!PS % (include any non-standard fonts here...) /Times-Roman findfont 300 scalefont setfont 10 10 moveto % position (Perl) true charpath % charpath makes outline 5 setlinewidth 1 setlinejoin 1 setlinecap [.1 6] 0 setdash % dotted line 0 0 0.5 setrgbcolor % in dark blue stroke showpage EOF close $ps; system "gs -q -dBATCH -dNOPAUSE -sDEVICE=pngalpha -r140 -g1000x500 -sO +utputFile=$outfile $tmpfile";

    (For this to work, you of course need to have GhostScript (gs) installed.)