senget76 has asked for the wisdom of the Perl Monks concerning the following question:

Hi
I have been trying to write text on a picture and nothing come up, I tried many style and approach.. still none. I am not sure what is wrong with it. My lucky guess will be the font, but I am not sure, perl does not return any error.

Another problem, is to position the text, the weird thing, how should I try to position text around if I could not see the text, stupid me!!!

Ok, here is sample of my code, help pleaseeeee

use Image::Magick; my($image); $image = Image::Magick->new; $image->Set(size=>'100x100'); $image->ReadImage('xc:white'); $text = 'Works like magick!'; $image->Annotate (font=>'tahoma.ttf', pointsize=>8, fill=>'green', tex +t=>$text, x=>20, y=>20); $image->Write('test.png');

Replies are listed 'Best First'.
Re: Magick: Text on the drawing
by crenz (Priest) on Apr 13, 2003 at 22:55 UTC

    You should check the return value of Annotate, e.g.

    $err = $image->Annotate(...); warn $err if !ref $err;

    See the error section on the ImageMagick Perl page for more info.

Re: Magick: Text on the drawing
by valdez (Monsignor) on Apr 13, 2003 at 23:59 UTC

    crenz suggested the correct method to check return values; now try to add @ in front of the font string, something like font => '@/path/to/tahoma.ttf'.

    HTH, Valerio

Re: Magick: Text on the drawing
by zentara (Cardinal) on Apr 14, 2003 at 12:18 UTC
    This works for me under Perl5.8.
    #!/usr/bin/perl use Image::Magick; my($image); $image = Image::Magick->new; $image->Set(size=>'200x50'); $image->ReadImage('xc:blue'); $image->Annotate( font=>'Generic.ttf', text=>"Hello, JOE!", pointsize=>28, stroke=>'red', fill=>'red', x=>20, y=>25); # this is on +e line $image->Write(filename=>"$0.png", compression=>'None');
strict?
by g00n (Hermit) on Apr 14, 2003 at 00:43 UTC
    #!/usr/local/bin/perl -w use strict; use Image::Magick; my($image); ... ...

    the pedant in me wants to add the above shebang line and strict?