Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Annotate and Image::Magick

by jeffpflueger (Beadle)
on Mar 26, 2001 at 02:23 UTC ( [id://67076]=perlquestion: print w/replies, xml ) Need Help??

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

I am having fair success using Image::Magick and PerlMagick for a web application that I am building. I am using the module and Image::Magick to save uploaded images to three different sizes ( a thumbnail, a medium and large sized jpegs) and Annotating the mid-sized and large sized. Problem is, I cannot seem to get Annotate to work very well...

#!/usr/local/bin/perl use Image::Magick; my $image = Image::Magick->new; my $x = $image->Read("robert.jpg"); warn "$x" if "$x"; $x = $image->Annotate(text=>'Hello...Are you there?'); warn "$x" if "$x"; $x = $image->Write("robertanno.jpg"); warn "$x" if "$x";

This is the simplest example I could make to demonstrate the problem that I'm having.

This loads robert.jpg and saves robertanno.jpg fine, but the Annotate returns the following error PERL:

sh: gs: command not found sh: gs: command not found

Any ideas about what is happenning? I've experimented with setting some of the other parameters for Annotate (font=>'font', gravity=>'whatever', fill=>'color' ) but I keep getting the same error. Is it that Image::Magick doesn't have something available to it that it expects? (font libraries....something?)

Any help would be great! Thanks!

An aside: By placing a

print "Error is happening either before or after me";

either before or after the Annotate command, the output is still the error and THEN what perl prints. Sort of weird. I'm curious why this is happenning. Its like the error is coming from Image::Magick maybe, and then Perl gets its chance to print its separte errors afterwards....I dunno though...any ideas on this?

Jeff Pflueger - Struggling Perl knowledge sponge

Replies are listed 'Best First'.
Re: Annotate and Image::Magick
by jlawrenc (Scribe) on Mar 26, 2001 at 05:42 UTC
    Jeff, Image::Magick is on my list of things to get into...

    But what is apparent, as others have mentioned, is that GhostScript is being called to annotate your image. Presumably gs is called to generate a bitmap rendering of your text which will then be overlayed on your image.

    You may want to look into building ImageMagick with TrueType support. To do this you need to ensure that you have the TrueType V2 library on your system and then recompile ImageMagick.

    To check for TrueType support at the least you could use the command:

    • use the command: ldd /usr/lib/libMagic.so
    If you see "libfreetype" in that list you should have support compiled in.

    I have a working build strategy for Image::Magick using the PerlMagick supplied in the distribution. If you pull down the latest perl module for ImageMagick you may encounter difficulties building it.

    As an alternative to ImageMagick I'd strongly encourage you to check out the GD package from Boutell.Com. I have gotten GIF annotations to work beautifully using it and I think for tasks such as you describe it might be a better (simpler) choice. (Take that comment with a grain of salt as I have not used Image::Magick successfully as of yet - largely due to time contraints.)

    Notes on building ImageMagick and Image::Magick

    FreeType - freetype.sourceforge.net
    A simple:

    ./configure --prefix=<wherever> make make test make install
    should suffice

    ImageMagick - www.imagemagick.org
    Some success building with:

    export PREFIX=<whereever> export CCFLAGS="-I$PREFIX/include/freetype2" export LDFLAGS="-L$PREFIX/lib" ./configure --prefix=$PREFIX \ --enable-shared \ --disable-static \ --with-modules \ --with-largefiles \ --with-magick-plus-plus \ --with-threads \ --enable-lzw=yes \ --without-fpx \ --with-perl=/usr/bin/perl
    You'll need to be root if you're installing into your OS's Perl libs. As with most things your mileage will vary depending on software confurations, etc.

    Let me know how you make out.

    Edit: chipmunk 2001-03-27

Re: Annotate and Image::Magick
by martian (Novice) on Mar 26, 2001 at 03:00 UTC
    gs is ghostscript - the postscript interpreter

    Presumably Image::Magick needs to use postcript to annotate the message.
Re: Annotate and Image::Magick
by coolmichael (Deacon) on Mar 26, 2001 at 04:34 UTC
    I don't know much about the sh: gs: command not found. Probably the shell missing something.

    I can offer a suggestion about aside, the print statement is being buffered in STDOUT by perl. I think if you put $|++; somewhere near the start of your script, you will disable outbuffering.

    $| is documented in perlvar.

    Michael,

    the blue haired monk.

Re: Annotate and Image::Magick
by Anonymous Monk on Mar 26, 2001 at 09:14 UTC
    I've only done this using ActivePerl on NT, so I don't know if it will work on other platforms, but something like this:
    $image->Annotate(font=>'@/full/path/to/font.ttf', x=>10, y=>10, points +ize=>24, pen=>blue, text=>'Ta-Daa.');
    might work... using any true type (maybe other formats too?) font.
Re: Annotate and Image::Magick
by knobunc (Pilgrim) on Mar 26, 2001 at 19:03 UTC

    Just so you know, I have found that the annotate function using TrueType fonts is very slow. About a second per string that I want to render.

    -ben

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found