neilwatson has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use GD; my $font_path='/usr/X11R6/lib/X11/fonts/truetype/verdana.ttf'; my $size = 18; 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) + || die "no cords $! $@"; #calc xsize my $xsize = $cords[2] - $cords[0] + 10; #calc $ysize my $ysize = $cords[7] - $cords[5] + 10; #create image my $image = new GD::Image ($xsize, $ysize) || die "no new image $! $@" +; #allocate colours my $black = $image->colorAllocate(0,0,0); #add true type text to image $image->stringTTF($black, $font_path, $size, 0, 5, 5, $text) || die "$ +! $@"; #send image to browser print $image->png;
I think it should work, there are not errors returned yet the browser returns a garbled corrupted image. Curiously, the @cords array only seems to have one entry $cords[0] = -21.
Any help you can offer would be appreciated. Thanks
Neil Watson
watson-wilson.ca
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Using GD and imageTTF
by merlyn (Sage) on Mar 29, 2003 at 15:56 UTC | |
by neilwatson (Priest) on Mar 29, 2003 at 17:12 UTC | |
|
Re: Using GD and imageTTF
by jasonk (Parson) on Mar 29, 2003 at 21:51 UTC |