Dougal
Dougal

Reputation: 55

How to create font preview image from font file on Linux?

I am wondering if there is any easy / possible way to create a "font preview image" file for a given font file on the Linux command line.

You know, like when you click on a font file in Linux or Windows file explorer and you get a little font preview window with "The quick brown fox jumps overs the lazy dog" in different sizes etc.

The input font file would be .PFB (Adobe type 1 font) or .TTF (TrueType font).

So, for example:

createfontpreviewimage somefont.pfb

[which creates somefontpreview.png or whatever]

Any thoughts? Or will I have to go down the hard work route of embedding the font file in a PDF document and generating the preview as a PDF document with PDFLib or some such?

Upvotes: 1

Views: 1776

Answers (3)

Robbie the best
Robbie the best

Reputation: 1

You can use fontpreview library and command line: https://github.com/MatteoGuadrini/fontpreview

A simple example in command line:

$ fp /tmp/noto.ttf

And more complex example:

$ fp /tmp/noto.ttf -t 'Hello Noto' -d 1000 1000 -b 'green' -f 'blue' -p 'lcenter' -z 50 -s /tmp/fp.png

The result is here: https://i.ibb.co/SfSmX44/fp.png

Instead if you use python, this script is the same result of the first command:

from fontpreview import FontPreview

fp = FontPreview('/tmp/noto.ttf')
fp.save('/tmp/fp.png')

For other examples, see the docs: https://fontpreview.readthedocs.io/en/latest/

Upvotes: 0

Artur Marnik
Artur Marnik

Reputation: 116

Write simple PHP script and use imagettftext() function to generate your images

Upvotes: 0

Related Questions