I'll include a URI here below for everyone to check out example images,
font files, etc. And also-- for those who care to take a look I'll
paste in a bit of Perl code which is used to render the text with my TTF
fonts and generate the images you'll see.
Now the type of output I get when using GD to generate strings with TTF
fonts is a series of boxes whose length is the length of the string I'm
trying to render. Examples--
<http://204.0.5.140/cgi-bin/archive.pl/pub/GDwoes>
(domain name 'atrixnet.com' does not currently resolve at this time,
which is the reason I use the IP address instead.)
Thanks Everyone!
<perlcode>
#!/usr/bin/perl
use strict;
use Futils;
my($f) = Futils->new();
use GD 1.20;
use GD::Text;
my($gd_text) = GD::Text->new() or die GD::Text::error();
GD::Text->font_path('D:/home/projects/Atrixnet/silverboxx/cgi-bin/fonts');
if ($gd_text->can_do_ttf()) {
print
(
qq[Well, GD::Text says I can handle TTFs! Isn't that a hoot!].
$f->newline()
);
}
else {
print
(
qq[No use trying, Can't fetchin do TTFs dangit!].
$f->newline()
);
}
print
(
qq[Oh, and BTW, GD is version $GD::VERSION, ].
qq[and GD::Text is version $GD::Text::VERSION.].
$f->newline()
);
$gd_text->
set_font
(
'Century Gothic.ttf',
12
)
or die($gd_text->error);
$gd_text->
set_text
(
qq[Hello fetchin world! Oh, and BTW, GD is version ].
$GD::VERSION
);
my($w,$h) = $gd_text->get('width', 'height');
print(qq[Width=$w and Height=$h].$f->newline());
if ($gd_text->is_ttf) {
print('Text is a TTF font!'.$f->newline());
}
else {
print('Text isn\'t a TTF font.'.$f->newline());
}
my(@ttf) =
(
'D:/home/projects/Atrixnet/cgi-bin/fonts/Verdana.ttf',
'D:/home/projects/Atrixnet/cgi-bin/fonts/Arial.ttf',
'D:/home/projects/Atrixnet/cgi-bin/fonts/Century Gothic.ttf',
);
my($im) = new GD::Image(400,250);
my($white) = $im->colorAllocate(255,255,255);
my($black) = $im->colorAllocate(0,0,0);
my($blue) = $im->colorAllocate(0,0,255);
my($red) = $im->colorAllocate(255,0,0);
$im-> # GD::Image object
stringTTF # object method GD::Image::stringTTF
( # ---begin args---
$black, # foreground color
$ttf[0], # TTF font file location
12, # pointsize to use when rendering string
0, # rotation angle of string (in radians)
26, # text position offset from left (x)
20, # text position offset from top (y)
'Hello world!' # string that GD will try to render
) # ---end args---
|| die($@); # read any errors from GD in '$@'
$im->
stringTTF
(
$red,
$ttf[1],
12,
0,
60,
100,
'Hello? Are you there, world?'
)
|| die($@);
$im->
stringTTF
(
$blue,
$ttf[2],
12,
0,
20,
80,
'Goodbye, cruel world.'
)
|| die($@);
$f->
write_file
(
'filename' => './foo.png',
'content' => $im->png,
);
</perlcode>
<perlcode output>
>F:\Perl\bin\perl.exe img.pl
Well, GD::Text says I can handle TTFs! Isn't that a hoot!
Oh, and BTW, GD is version 1.27, and GD::Text is version 0.80.
Width=632 and Height=10
Text is a TTF font!
>Exit code: 0
</perlcode output>
[output also includes the images I create with this code; see URIs above
for examples of the images created.]
Thanks Everyone!
--
-Tommy Butler, consultant
Atrixnet, for Internet Business Software
6711 Forest Park Drive
Dallas, TX
76001
--
I need work!
http://www.atrixnet.com/contracting/
Request a script!
mailto:gimm...@atrixnet.com
Get help with code!
mailto:hel...@atrixnet.com
Get my resume!
http://www.atrixnet.com/resume/
Visit the open source Perl archives at Atrixnet.
http://www.atrixnet.com/pub/