how to use font in imagemagick convert 

Subject: how to use font in convert(imagemagick)?
Newsgroups: gmane.linux.debian.user
Date: 2007-03-12
> I want to use the '-font' option of convert to annotate images.  I'm not
> sure if convert can deal with locales other than iso-8859, and what's the
> syntax of the font name?

I guess you haven't been to Anthony's helpful Text to Image Handling Examples http://www.imagemagick.org/Usage/

Check it out. Want to use the font of your own? No problem. Want to use Chinese font? No problem, there is even an example right using Chinese font. Want to use a font without registering to ImageMagick? No problem. Check it out, the answers are all there.

Moreover, if you still have any problem that is not covered, I suggest you subscribe to the ImageMagick User List http://www.imagemagick.org/mailman/listinfo/magick-users

An *extremely* helpful mlist. Well worth the trouble of the email registration. you will find Anthony answering questions there himself. You throw in a question to the mlist, no matter how hard it is, an answer will (magically) come out… :-)

T

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

Print a sample of all fonts 

Newsgroups: gmane.linux.debian.user
Date: Sun, 27 Jan 2008
> is there a way to have gimp or whatever print a sample of each
> font on the system without manually writing them all out? tia.

Both answers so far seem to me only allow you to view the font one by one, which involves a lot of clicking if you want to see each font on the system. Check out

for the 2 methods to document fonts via ImageMagick, one native, and one char-map way.

For example, to document all the fonts on the system, you can

slocate -ir '\.ttf$' | xargs -i echo 'convert {} /tmp/`basename {}`.gif' | sh

then print out the images.

xpt

Controlling line spacing 

Newsgroups: gmane.comp.video.image-magick.user
Date: Mon, 25 Jun 2007
| I use the "-shade" operator to create beveled fonts. Ref:
| http://www.imagemagick.org/Usage/fonts/#bevel[]
|
| The problem is that I need the text to be on 2 lines, but the line spacing
| is too wide for me, since my image is small:
| http://xpt.sourceforge.net/images/xpt.gif[]
|
| I'm wondering if there is any way to reduce the line spacing in this case?

Two ways. Do the two words separatally trim and center append.

or somehow chop out the unwanted 'gap'. Look for the divide_vert script in http://www.imagemagick.org/Usage/scripts/ in a day or so. I just re-wrote it to not use so many temporary files, and speed it up.

PS: I'l like to see that added to MagickCore library. :-)

Anthony Thyssen

Controlling line spacing 

| > The problem is that I need the text to be on 2 lines, but the line spacing
| > is too wide for me, since my image is small:
|
| Forgot to say, this is how I did it:
|
|  convert -size 220x25 xc:black -font Candice -pointsize 14 -fill white \
|  -gravity center -annotate 0 'line1\nline2' -shade \
|  140x60 xpt.gif
|
| Candice is a symlink to a ttf font file.

Why? define it properly in IM… See the top level IM example page. http://www.imagemagick.org/Usage/#font

You can then add all your fonts into IM with nice names.

| The result is at,
|
| > http://xpt.sourceforge.net/images/xpt.gif[]
| >
| > I'm wondering if there is any way to reduce the line spacing in this
| > case?

The pointsize of a font represents its line spaceing. that is its actual defination!!!!

It is then up to the font designers on how you want to fill that space. And most of them do a horrible job of using that space!

But I knwo what you want. If you are always using the same font and pointsize, you can '-chop' out the extra space….

For example 5 rows of pixels from the 14th pixel form the top…

convert http://xpt.sourceforge.net/images/xpt.gif \
   -chop 0x5+0+14 xpt_squeezed.gif

Alternatively in a couple of days a new script will be up in http://www.imagemagick.org/Usage/scripts/ called "divide-horiz" Which is a quick script I wrote on the weekend to solve a problem I was having. The script works, but does not check that each line also has the same color :-(

This divides an image into multiple images divided by lines of constant color. That is the 'gaps' in an image, That is images will become a list of images of the form

blanks, stuff, blanks, stuff,....

which if you -append would re-form the original image. Note if the image was 'trimmed' the first image would not be 'blank'.

You only need to remove or 'fix' the size of the blank 'gap' images.

I am wanting to get the funcationality of this script built into IM as a -divide-horiz option. Which along with a -layers RemoveBlank operation can be used to delete the blank images that are all one color.

Anthony Thyssen