in reply to Annotate with Image::Magick

I've had problems writing text to images with Image::Magick, and realized later on that I was not pointing to the right font file, and it was just.. printing nothing.

Replies are listed 'Best First'.
Re^2: Annotate with Image::Magick
by JayBee (Scribe) on Nov 11, 2007 at 18:28 UTC
    I tried all kinds of fonts, some from the book, some from other forums, and some from the ImageMagick website. Non worked, so I thought if I leave it undeclared, it would default to some system font...
    Frankly, I don't even know where the fonts are to lookup, so I can be certain I'm using a valid one...
      I had the same problem, and banged my head repeatedly until I came to a solution: explicitly provide the path to a valid font. Here's a working example (for me):
      #!/usr/bin/perl use Image::Magick; $q = Image::Magick->new(); $q->Set(size => '80x20'); $q->Read('xc:white'); $q->Annotate( text => 'Hi There', font => '/usr/share/fonts/truetype/freefont/FreeSerif.ttf', pointsize => 18, fill => 'black', gravity => 'Center', ); $q->Write('whatever.png'); # who needs error checks?!? ;)
      As you can see, TrueType fonts are welcome (you can find some here if you don't have one already).

      Flavio
      perl -ple'$_=reverse' <<<ti.xittelop@oivalf

      Io ho capito... ma tu che hai detto?
        PERFECT
        That's they way to do it!
        Looks like, I needed a guide to where the fonts are: I found a working one here: '/usr/share/fonts/hebrew/Aharoni-Book.pfa'
        There are others with '.afm' extension, that don't seem to work, but who cares, I'm Excited as long as even '.pfa' works!
        Whoohoo (8D