Page 1 of 1

Can`t write words into image(solved)

Posted: 2008-09-02T23:14:09-07:00
by tujchl1223
I want to add some words into image using image::magick, the code is below:
#!/usr/bin/perl -w
use Image::Magick;
$im = Image::Magick->new(size => '1300x5000');
$im->Read('xc:white');
$im->Set(stroke => 'red');
$im->Draw(primitive => 'rectangle',points => '0,0 399,299');
$text = 'Works like magick!';
$im->Annotate(font=>'times.ttf', pointsize=>40, fill=>'green', text=>$text);
$im->Write('png:GDExample.png');
the code is running well and even I can see the retangle on the image, but I can`t find the words!
Could you help me?
Thanks a lot!

Re: Can`t write words into image

Posted: 2008-09-03T08:12:14-07:00
by el_supremo
I think you need to specify a coordinate to Annotate. It is probably defaulting to 0,0 which is the top left of the image and most text won't be visible because it is drawn above the baseline.
As a starting point, try adding
x=>50, y=>50,
to the Annotate call.

Pete

Re: Can`t write words into image

Posted: 2008-09-03T16:07:25-07:00
by anthony
Or set gravity to something else but none. For example NorthWest
is NOT the same as none, generally Center is good.

Re: Can`t write words into image

Posted: 2008-09-03T18:10:06-07:00
by tujchl1223
it works!
Thank you but the most important things in annotate method ,I think, is to specify the type of characters. the code will not work even you set up everything but it.

tujchl

Re: Can`t write words into image

Posted: 2008-09-04T16:06:09-07:00
by anthony
tujchl1223 wrote:it works!
Thank you but the most important things in annotate method ,I think, is to specify the type of characters. the code will not work even you set up everything but it.

tujchl
What do you mean by "type of characters"?
The font?

Actually I think all the settings are all important, so as to get the desired result.