How to Specify Font in ImageMagick Convert?
This article provides a quick overview and practical guide on how to
specify a custom font type when adding text to an image using the
ImageMagick convert command. You will learn the exact
syntax required, how to list the available fonts on your system, and how
to troubleshoot common path issues to ensure your text renders
correctly.
The Basic Syntax
To specify a font type in ImageMagick, you use the -font
setting followed by the font name or the direct path to the font file.
This setting must be placed before the
-annotate or -draw commands where the text is
actually defined.
Here is the standard command structure:
magick convert input.jpg -font Arial -pointsize 36 -fill white -annotate +50+50 "Hello World" output.jpgNote: In ImageMagick v7 and later, the
convertcommand is officially replaced bymagick, thoughmagick convertstill works for backwards compatibility.
Specifying Fonts by Name vs. TrueType Path
You can define the font in two distinct ways depending on whether the font is registered with ImageMagick or sitting in a specific directory.
- By System Name: If the font is already installed on your system and recognized by ImageMagick, you can call it directly by its standard name.
-font Helvetica-Bold- By Direct File Path: If you want to use a specific
TrueType (
.ttf) or OpenType (.otf) file that isn’t installed system-wide, provide the absolute path to the file prefixed with an@symbol (the@is optional in newer versions but ensures compatibility).
-font "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"How to Find Available Font Names
If you aren’t sure what names ImageMagick recognizes on your current machine, you can generate a complete list of configured fonts by running the following command in your terminal:
magick -list fontThis will output a list of font names, families, and glyph paths that
you can safely use directly with the -font flag without
needing to look up their exact directory paths.