
ttfsample
ttfsample is a small utility to create a sample image of a Truetype TTF font or Opentype OTF font.
For the License see LICENSE
The program comes with a GNU Free Sans and Serif Bold True Type font which
are under the GNU Free Font license.
There are a couple of options, primary being, that you can supply the text to be
printed as an argument. But there is also a sensible default (see image).
When run with the font Arial Narrow, the result will look like this:

The name of the font will always be included, printed with a
boring font, GNU FreeSansBold, that is always
readable even if the font has only symbols.
Author: Stefan Schröder, 2019 - 2024
Changelog
0.4.0: we have changed the options. Now the font files are to
be used as parameters, whereas the desired output string is the
new option -wanted. This feels more natural.
Install and quickstart
go install github.com/StefanSchroeder/ttfsample/ttfsample@latest
ttfsample somefont.ttf someotherfont.ttf
will create a PNG image in the newly created directory png/.
Build
go build .
will do the trick if your Go development environment is setup properly.
Parameters
ttfsample somefont.ttf someotherfont.ttf
This command will create two sample files, one for each font in
the png directory, which will be created for you.
Options
-wanted "Hello font"
-wanted "First line\nSecond line"
Print the text Hello font on the canvas instead of the default
alphabet. You can use \n to insert a newline.
-hinting <none|full>
Set hinting to none to disable hinting. Default is full.
-dpi INTEGER
The default value for dpi is 72. Set dots per inch.
-outdir STRING
The outdir option defines the output directory where the image will be stored.
-size INTEGER
-size sets the font size in points. Default is 100. Use responsibly.
-spacing FLOAT
-spacing set the distance between two lines. Defaults to 1.5.
-walk PATH
The -walk option recursively searches the directory tree for fonts to print
starting from PATH and not following symlinks.
-width INTEGER
The -width option defines the width of the generated PNG image.
The default is 2000. If you make the width too small, the image
will be simply cut off. Setting this value to 0 is illegal.
The absolute value will taken, so you can use negative numbers,
but why would you do that?
-height INTEGER
The -height option defines the height of the generated PNG image.
The default is 800. If you make the height too small, the image
will be simply cut off. Setting this value to 0 is illegal.
Testing
Tested on Windows and Linux.
Run
go test