Can`t write words into image

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
tujchl1223

Can`t write words into image

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
Ryland

Re: Can`t write words into image

Post by Ryland »

My guess is that since you didn't define x or y parameters, the text is being drawn at 0,0. Since the origin of a text annotation is at the bottom left (assuming text is left justified), this puts it off the screen. Try setting x and y to positive integers and see if that fixes it.

Example:

Code: Select all

$im->Annotate(font=>'times.ttf', pointsize=>40, fill=>'green', text=>$text, x=>10, y=>50);
Post Reply