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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |