Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Generating text as an image with PerlMagick

by ralphch (Sexton)
on Nov 30, 2006 at 14:42 UTC ( #586946=perlquestion: print w/replies, xml ) Need Help??

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

Hi,

I'm trying to generate an image based on a text string with PerlMagick, but can't seem to get it working. This is to be used as a verification code for securing a web form. Here's the code:

#!/usr/bin/perl use Image::Magick; $image = Image::Magick->new; $image->Set(size=>'150x50'); $image->ReadImage('xc:white'); $text = "This is a test"; $image->Annotate(pointsize=>40, fill=>'red', text=>$text); print "Content-type: image/gif\n\n"; print $image->Write('gif:-');

Whenever I run the script through the browser, all I see are a couple of thin red lines (no text).

I've searched all over the Internet but can't seem to find any clear explanation on how to use this Annotate method.

Any help will be greatly appreciated.

Thanks,
Ralph

Replies are listed 'Best First'.
Re: Generating text as an image with PerlMagick
by themage (Friar) on Nov 30, 2006 at 14:53 UTC
    Hi ,

    What you are looking at is the last line of the letters you are trying to put in the image.

    Try this:
    $image->Annotate(pointsize=>40, fill=>'red', text=>$text, y=>40);
    TheMage
    Talking Web
Re: Generating text as an image with PerlMagick
by Fengor (Pilgrim) on Nov 30, 2006 at 15:03 UTC
    You have got to set the x=> and y=> parameters of annotate accordingly so that the text is visible in the pic. as it is you only see the lower end (the red lines). See the official example scripts for full parameters of annotate

    --
    "WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
    -- Terry Pratchett, "Reaper Man"

Re: Generating text as an image with PerlMagick
by derby (Abbot) on Nov 30, 2006 at 14:52 UTC

    Not too helpful, but have you looked at GD::SecurityImage. It allows for ImageMagick as a back end and has some notes about bugs with some versions of ImageMagick not rendering fonts correctly.

    -derby
Re: Generating text as an image with PerlMagick
by GrandFather (Saint) on Nov 30, 2006 at 20:45 UTC
      i think Rename some jpegs, make thumbnails would fit quite nicely in that list to. Helped me writing a little gallery app for some friends of mine a few years back on a lan party.

      --
      "WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
      -- Terry Pratchett, "Reaper Man"

Re: Generating text as an image with PerlMagick
by ralphch (Sexton) on Nov 30, 2006 at 23:10 UTC

    Hi, thanks for all of your replies! The issue was with the positioning of the text, so now it's showing correctly :-)

    Thanks again and I'll keep all of these resources in my bookmarks since they're very useful.

    Regards,
    Ralph

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://586946]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-09-27 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?