Thanks Merlyn,
Here is the completed code:
use strict; use warnings; use GD; my $font_path='/usr/X11R6/lib/X11/fonts/truetype/verdana.ttf'; my $size = 32; my $text="Foo Bar!"; #get cords for the image box. Cords are returned like this: #x4,y4 ---------------------------- x3,y3 #| | #| | #| | #| | #x1,y1 ---------------------------- x2,y2 my @cords = GD::Image->stringTTF(0, $font_path, $size, 0, 0, 0, $text) + or die "no cords $! $@"; #calc size along x and y axis my $xsize = $cords[2] - $cords[0] + 5; my $ysize = $cords[1] - $cords[7] + 5; #calc start cords my $xstart = ($xsize - ($cords[2] - $cords[0])) / 2; my $ystart = ($ysize - ($cords[1] - $cords[7])) / 2 - $cords[7]; #create image my $image = new GD::Image ($xsize, $ysize) or die "no new image $! $@"; #allocate colours my $trans = $image->colorAllocate(200,200,200); $image->transparent($trans); my $black = $image->colorAllocate(0,0,0); #add true type text to image $image->stringTTF($black, $font_path, $size, 0, $xstart, $ystart, $tex +t) or die "$! $@"; #send image to browser print $image->png;

Neil Watson
watson-wilson.ca


In reply to Re: •Re: Using GD and imageTTF by neilwatson
in thread Using GD and imageTTF by neilwatson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.