Thursday, June 3, 2010

manually add a new font to Linux and use in imagemagick

There are various locations in GNU/Linux in which fonts can be kept. These locations are defined in /etc/fonts/fonts.conf;

standard ones include /usr/share/fonts, /usr/local/share/fonts, and /home/<username>/.fonts (where <username> is your user name).

The easiest way to install a truetype font is to go to (as a side if you are wondering why I specified there are others like opentype):

cd /usr/share/fonts/truetype

Then create a new directory, nameing it whatever you like (in case you'll need to backup your fonts personal fonts) I choosed ibc.

#sudo mkdir  /usr/share/fonts/truetype/ibc

Copy your fonts into the directory,

#sudo cp /tmp/IDAutomationHC39M.ttf /usr/share/fonts/truetype/ibc

rebuild the font information cache files:

#sudo fc-cache -f -v
/usr/share/fonts/truetype/ibc: caching, new cache contents: 1 fonts, 0 dirs


#fc-list |grep ID

<!> Note: After you install a new font,  make sure that programs in which you want to use the new fonts can recognize them by closing and reopening them; note that some programs may require you to log out and log back in.

After the previous steps if you need to use the fonts in imagemagick and dont want to add by hand use this perl script.


# convert -list font|grep -i ibc
   glyphs: /usr/share/fonts/truetype/ibc/IDAutomationHC39M.ttf

and use it:
#convert -size 200x150 -background white -font IDAutomationHC39M  -gravity center label:IBC /tmp/ibctest.gif;display /tmp/ibctest.gif
The easiest place for people to put their fonts is /home/<username>/.fonts. If you have not already done so, create this folder and drop your fonts into the folder.
However, fonts that are added by either of the ways above will only be available for one user.

To make them available system-wide, drop them to the directory /usr/share/fonts. (Note: If you're on Kubuntu you may have to cd to /usr/share/fonts and run mkfontscale, mkfontdir, fc-cache after this. Check the man.)

Here you can find a longer explanation of the previous quick steps if you wish.

cheers Alex

MyLinux blog:

No comments:

Post a Comment