imager sample for text

J

jcharth

hello anyone has a sample of rendering text in to a jpg using imager. I
installed imager in my box but the code seems to show only a black
patch

my $font = Imager::Font->new(file=>"foo.ttf");

$img->string(x => 50, y => 30,
string => "$randstr",
font => $font,
size => 10,
aa => 1,
color => 'white');
 
Z

zentara

hello anyone has a sample of rendering text in to a jpg using imager. I
installed imager in my box but the code seems to show only a black
patch

my $font = Imager::Font->new(file=>"foo.ttf");

$img->string(x => 50, y => 30,
string => "$randstr",
font => $font,
size => 10,
aa => 1,
color => 'white');

You probably need to install the Freetype2 library to
support ttf files. Also make sure you have the ttf file
in the script directory, or else give the full path to the font file.

This works on my machine:

#!/usr/bin/perl
use warnings;
use strict;
use Imager;

my $img = Imager->new(xsize=>400,ysize=>300);
$img->box(filled=>1, color=>"ffffff"); #fill the background color

my $blue = Imager::Color->new("#0000FF");

my $font = Imager::Font->new(
file => 'Generic.ttf',
index => 0,
color => $blue,
size => 30,
aa => 1);

$img->string(
font=>$font,
text=>'This is a test string',
x=>20,
y=>70);

$img->write(file=>"$0.jpg", type=>"jpeg") or die "Cannot write file: ",
Imager->errstr;
__END__


zentara
 
J

jcharth

Thanks. Looks like I had ttf missing :( i notice when i recompiled
imager works. great now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top