It seems Imager::Font has some memory leak. On my system, I can only create about 1080 fonts at a time. That's why I use this with perl mkhtml >> index.html, and start it over 6 times. My ttf library has >5000 fonts.

#!/usr/bin/perl -w use strict; use Font::TTF::Font; use Imager qw(:handy); my $b = NC(0,0,0); my $w = NC(255, 255, 255); my $s ="The quick brown fox jumps over the lazy dog. 0123456789 {[()]} + @%&*?!"; my $e = 0; opendir D, '.'; while (defined(my $f = readdir D)) { next if $f !~ /ttf$/i; next if -e "$f.jpg"; print STDERR "$f\n"; my $n = Font::TTF::Font->open($f) || $f; $n = $n->{name} || $f if ref $n; $n = $n->read->find_name(4) || $f if ref $n; my $F = NF(file => $f, aa => 1) or $e++,print(STDERR $Imager::ERRS +TR),next; my @b = $F->bounding_box(string => $s); my ($x, $y) = ($b[2] - $b[0], $b[3] - $b[1]); my $i = Imager->new(xsize => $x, ysize => $y) or next; $i->box(filled => 1, color => $w); $i->string(font => $F, string => $s, x => $b[0], y => $b[3], color + => $b); $i->write(file => "$f.jpg"); print qq{$f - $n<br><img src="$f.jpg" alt="$f" width=$x height=$y> +<hr>\n}; } print STDERR "Failed: $e\n"

Replies are listed 'Best First'.
Re: TrueType font gallery
by Louis_Wu (Chaplain) on Nov 09, 2002 at 19:44 UTC
    It seems that you've missed a few characters in $s - -_=+\|/,:;'<>`~^$#. Those seem necessary for much writing, and most coding. :)

    So it seems that the line should be:
    $s = "The quick brown fox jumps over the lazy dog. 0123456789 {[()]} @%&*?! -_=+|/,:;'<>`~^$# \\ \" ";

    The group of symbols starting with -_ are normal, I had to escape the \ and the " to keep them in the string.

      It seems that you've missed a few characters

      The set of characters was limited on purpose. Ideally, the fox/dog string would be in allcaps too, and some non-ascii characters like the euro-symbol would also be nice.

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

        Oh, I thought that the alpha characters might get auto-caps in the font program. Hmm, did you limit the class of characters for the purposes of this example, or in your personal use? And if in your personal use, why?
Re: TrueType font gallery
by december (Pilgrim) on Jun 04, 2003 at 17:48 UTC

    'lo,

    I had almost the same problem (could be because I kinda borrowed some of this code in one of my scripts ;) ). The problem seemed to be Font::TTF::Font, $n->release() did the trick.

    Don't forget that in your example you change the original reference, so you don't have any method 'release' anymore (I forgot that initially).

    my $n = Font::TTF::Font->open($f) || $f; $tmp = $n->{name} || $f if ref $n; $tmp = $tmp->read->find_name(4) || $f if ref $n; $n->release() if ref $n;
    This brought back memory usage from ~25mb (crash at 1020 fonts) to ~6mb (all my fonts, 1035).


        december

    PS: Where did you find the find_name(4) reference? I haven't found any documentation about the exact usage of find_name and the meaning of its $nid parameter...

      Where did you find the find_name(4) reference? I haven't found any documentation about the exact usage of find_name and the meaning of its $nid parameter...

      This is specified in the truetype/opentype specs. tt/ot fonts are divided into tables. "name" is one of those tables.

      Look here for details: http://www.microsoft.com/typography/otspec/name.htm

      PS: Where did you find the find_name(4) reference? I haven't found any documentation about the exact usage of find_name and the meaning of its $nid parameter...

      I didn't. Just tried values until it returned something reasonable. One does stupid things when documentation is lacking.

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

        Heh. That's basically what I did, too. Nowhere a reference to those strings to be found.

        And, out of curiosity, does it work (or did time make this irrelevant)?

Re: TrueType font gallery
by naChoZ (Curate) on Jun 04, 2003 at 18:20 UTC
    I'm partial to the pangram:

    The five boxing wizards jump quickly.

    Mostly because I'm sick of that damn lazy mutt.

    ~~
    naChoZ

      You don't have a minuscule 't' in it. The same problem as with 'Playing jazz vibe chords quickly excites my wife.', my personal favorite. :)

      The string I use most often though is 'The quick brown fox jumps ovér thč lazy dög.'. It shows if the font has all characters, and if it has capitals, accents, umlauts and a dot, in which case most fonts will be usable for most iso-8859-15 charset users (default latin1 + euro, used by most European languages including Dutch and French, which are relevant to me).

      *RANT* I find it hard to understand how one can design a whole font, character by character, which takes an incredible amount of work to do right, and then not take the time to at least just copy the characters that need umlauts and put two dots on top.

        You don't have a minuscule 't' in it. The same problem as with 'Playing jazz vibe chords quickly excites my wife.', my personal favorite. :)

        Good point. Well, a terse word could be added of course.

        The five boxing wizards jumped too quickly.

        ~~
        naChoZ