#!/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::ERRSTR),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