Can`t write words into image(solved)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tujchl1223

Can`t write words into image(solved)

Post 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!
Last edited by tujchl1223 on 2008-09-03T18:15:01-07:00, edited 1 time in total.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Can`t write words into image

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Can`t write words into image

Post by anthony »

Or set gravity to something else but none. For example NorthWest
is NOT the same as none, generally Center is good.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
tujchl1223

Re: Can`t write words into image

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Can`t write words into image

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply