in reply to Re: Annotate with Image::Magick
in thread Annotate with Image::Magick

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...

Replies are listed 'Best First'.
Re^3: Annotate with Image::Magick
by polettix (Vicar) on Nov 11, 2007 at 20:54 UTC
    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
        Ok, I even have more for you, fasten your seat belt.

        (Re-)Looking at the docs, I (re-)saw that it's possible to have a list of the known-of fonts like this:

        perl -MImage::Magick -le ' print join("\n* ", "installed fonts:", Image::Magick->QueryFont())' installed fonts: * AvantGarde-Book * AvantGarde-BookOblique * AvantGarde-Demi * AvantGarde-DemiOblique * Bookman-Demi * Bookman-DemiItalic * Bookman-Light * Bookman-LightItalic * Courier * Courier-Bold * Courier-BoldOblique * Courier-Oblique * Helvetica * Helvetica-Bold * Helvetica-BoldOblique * Helvetica-Narrow * Helvetica-Narrow-Bold * Helvetica-Narrow-BoldOblique * Helvetica-Narrow-Oblique * Helvetica-Oblique * NewCenturySchlbk-Bold * NewCenturySchlbk-BoldItalic * NewCenturySchlbk-Italic * NewCenturySchlbk-Roman * Palatino-Bold * Palatino-BoldItalic * Palatino-Italic * Palatino-Roman * Symbol * Times-Bold * Times-BoldItalic * Times-Italic * Times-Roman
        So I did have those fonts "installed" in some way or another. But still I was unable to use them.

        An independent check with the montage program, on the other hand, showed that these fonts are known to it and that it could actually use them. So they also had to be somewhere. By the way, you can ask the list of fonts like this:

        shell$ mogrify -list Font # or Type, for older IM Path: /usr/lib/ImageMagick-6.0.6/config/type-ghostscript.mgk Name Family Style Stret +ch Weight ---------------------------------------------------------------------- +---------- AvantGarde-Book AvantGarde Normal Norma +l 400 AvantGarde-BookOblique AvantGarde Oblique Norma +l 400 AvantGarde-Demi AvantGarde Normal Norma +l 600 AvantGarde-DemiOblique AvantGarde Oblique Norma +l 600 Bookman-Demi Bookman Normal Norma +l 600 Bookman-DemiItalic Bookman Italic Norma +l 600 Bookman-Light Bookman Normal Norma +l 300 Bookman-LightItalic Bookman Italic Norma +l 300 Courier Courier Normal Norma +l 400 Courier-Bold Courier Normal Norma +l 700 Courier-BoldOblique Courier Oblique Norma +l 700 Courier-Oblique Courier Oblique Norma +l 400 Helvetica Helvetica Normal Norma +l 400 Helvetica-Bold Helvetica Normal Norma +l 700 Helvetica-BoldOblique Helvetica Italic Norma +l 700 Helvetica-Narrow Helvetica Narrow Normal Conde +nsed 400 Helvetica-Narrow-Bold Helvetica Narrow Normal Conde +nsed 700 Helvetica-Narrow-BoldOblique Helvetica Narrow Oblique Conde +nsed 700 Helvetica-Narrow-Oblique Helvetica Narrow Oblique Conde +nsed 400 Helvetica-Oblique Helvetica Italic Norma +l 400 NewCenturySchlbk-Bold NewCenturySchlbk Normal Norma +l 700 NewCenturySchlbk-BoldItalic NewCenturySchlbk Italic Norma +l 700 NewCenturySchlbk-Italic NewCenturySchlbk Italic Norma +l 400 NewCenturySchlbk-Roman NewCenturySchlbk Normal Norma +l 400 Palatino-Bold Palatino Normal Norma +l 700 Palatino-BoldItalic Palatino Italic Norma +l 700 Palatino-Italic Palatino Italic Norma +l 400 Palatino-Roman Palatino Normal Norma +l 400 Symbol Symbol Normal Norma +l 400 Times-Bold Times Normal Norma +l 700 Times-BoldItalic Times Italic Norma +l 700 Times-Italic Times Italic Norma +l 400 Times-Roman Times Normal Norma +l 400
        Note the
        Path: /usr/lib/ImageMagick-6.0.6/config/type-ghostscript.mgk
        line: this is the file where the "known fonts" are configured.

        Then I suddenly remembered that to install Image::Magick you can't go through CPAN, but you have to recompile the whole ImageMagick... click! The ImageMagick programs I'm using are those that came with my Linux distro, but the Image::Magick Perl stuff isn't. So, I went where I installed this recompiled IM (in /opt/ImageMagick), and used the path above to look for the font configuration file, which happens to be in /opt/ImageMagick/lib/ImageMagick-<version>/config. The file was called a bit differently - xml extension instead of mgk - but the format was the same. Except that the paths inside were all wrong!

        Well, it was easy at this point. I simply copied the type-ghostscript.mgk file from the old IM to the type-ghostscript.xml file in the new IM, and voilą - "standard" fonts work now, even without giving the full path.

        Due to the Image::Magick installation process, I suspect that you could suffer from a similar problem. Hope this helps!

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

        Io ho capito... ma tu che hai detto?