Use ImageMagick to document font 

Newsgroups:  gmane.comp.video.image-magick.user
Date:        Wed, 29 Nov 2006 19:56:48 -0500

I was trying to follow the most comprehensive ImageMagick Usage Examples at http://www.imagemagick.org/Usage/

to document the fonts that I collected. E.g.,

cat template.text | convert -background none -box white -pointsize 48 text:- -trim +repage -border 3 -flatten -size 800x -font walkwayultraexpandbold.ttf walkwayultraexpandbold.p48.gif

However, there are problems.

And here is my template.text:

$ cat template.text
M W M W M W M W M W M W M W M W
  ! " # $ % & ' ( ) * + , - . /
0 1 2 3 4 5 6 7 8 9 : ; < = > ?
@ A B C D E F G H I J K L M N O
P Q R S T U V W X Y Z [ \ ] ^ _
` a b c d e f g h i j k l m n o
p q r s t u v w x y z { | } ~

As you can see, I tried to fix the problem myself, eg, adding the 1st redundant-but-wide line, use -size 800x, etc. but the problem is still there.

thanks a lot

Use ImageMagick to document font 

| So, the ultimate question is, is it possible to document fonts using
| ImageMagick?

If you read a font file as a image. IM will generate a standard 'font description' image…

convert arial.ttf   arial_index.jpg

Note nether your method or the above will document all the acpects of a font, particualrly some 'interesting' symbol fonts.

Basically many modern fonts have unicode characters implemented making the number of characters in common fonts extrememly large!

As for mono-spacing. The only suggestion is do each character as a seperate image and "montage" all the characters together. That will probably need a looped script of some form.

for i in A B C D; do
  convert -font WingDings -pointsize 24 -label $i label:$i miff:-
done | montage - -font Arial -frame 5  -geometry +2+2 WingDings_montage.gif

However in recent versions of Im I have noticed that label: adds extra space on the left and right sizes of the text strings.

You may like to look at using a canvas and the 'undercolor' -box setting… to trim the individual characters….

Undercolor Box
    http://www.imagemagick.org/Usage/text/#box
  Auto Sized using 'Undercolor Box'
    http://www.imagemagick.org/Usage/text/#size
  Determining Font Metrics, without using an API
    http://www.imagemagick.org/Usage/text/#font_info

And PLEASE let us know what you come up with…

Anthony Thyssen

Use ImageMagick to document font 

> | I was trying to document the fonts that I collected. E.g.,
>
> If you read a font file as a image. IM will generate a standard 'font
> description' image...
>
>    convert arial.ttf   arial_index.jpg

Yes, that works. Just for the record, I choose to convert to .gif, though proprietary, it is about 3 times smaller than .jpg files.

> [...]
>
> As for mono-spacing. The only suggestion is do each character as a
> seperate image and "montage" all the characters together.  That will
> probably need a looped script of some form.

I don't have sufficient understanding of the montage/convert to carry out the script. Anyway, the above method is good enough for me.

thanks a lot

Use ImageMagick to document font 

> If you read a font file as a image. IM will generate a standard 'font
> description' image...
>
>    convert arial.ttf   arial_index.jpg
hmm... one problem, I notice that not all number characters are shown.
Only 0\~6 are in the description image, 7\~9 have been cut out. I tried 2
fonts, both are the same.

T

Use ImageMagick to document font 

>> And PLEASE let us know what you come up with...
>
> I'm only half the way [...]

OK, here is the closest that I can get:

perl -e 'foreach $c (0x20..0x7e) { print("convert -font DOC_FONT -pointsize 24 label:\"". chr($c). "\" miff:-\n") }' | sed '/'\''/d; /[\\`]/d; s/"\([*@"]"\)/"\\\1/' | sh | montage - -geometry +0+4 DOC_FONT.gif

substitute DOC_FONT to your desire.

T

Use ImageMagick to document font 

|  perl -e 'foreach $c (0x20..0x7e) { print("convert -font DOC_FONT -pointsize 24 label:\"". chr($c). "\" miff:-\n") }' | sed '/'\''/d; /[\\`]/d; s/"\([*@"]"\)/"\\\1/' | sh | montage - -geometry +0+4 DOC_FONT.gif

Very good. Though as I mentioned, rather than using label, it may be better to use a undercolor box with -annotate on a larger canavs.

You may also like to add a '-trim +repage' to the generating commands.

You could also change the perl script to convert a input text file to appropriate convert commands, (one for each character), then output 'null' padding charcaters to bring lines up to 80 characters (or some other pre-determine line length) before executing and feeding the result to montage, with a "-tile 80x" setting.

The montage basically is used to convert the individual proportional characters into a table of fixed width characters.

By change it to be a line filter you are not limiting the command to a single table. Instead allowing you to use the table output of commands like

http://www.imagemagick.org/Usage/scripts/graphics_utf

Anthony Thyssen

Use ImageMagick to document font 

| hmm... one problem, I notice that not all number characters are shown.

I wrote a script as I had described, and processed the output of the whole latin unicode character range.

Charcaters I had problems with…

controls         0x00 to 0x20
space            proportional fonts produce a very large space!
single quote     does not wrap in shell single quotes
at symbol        IM treats a first '@' symbol in a string as special.
Code 0xA0        I think IM treats this meta-@ like an '@' symbol

The Script is in.. http://www.imagemagick.org/Usage/scripts/text2img_fixed

try… (using the graphics_utf script also in same directory)

graphics_utf 0020 0080 | text2img_fixed -l 60  output.gif

which is basically what you were trying to achieve :-)

Replace output.gif with x: for a on screen display. Could take some time as lots of commands are being processed.

Line length is fixed to 70 unicode characters.

Anthony Thyssen