An API which generates PNGs to showcase fonts
This API is made to be used with an upcoming app. The API generates a static paragraph image or a code image based on the fonts and weights specified by the user.
If you wish to implement this API for yourself, do the following:
- Create a folder named fonts in the root folder. Store the fonts as per the following format: /fonts/{FontFamily}/{FontFamily}-{FontWeight}.ttf For eg:
fonts
--- RobotoSlab
------ RobotoSlab-400.ttf
------ RobotoSlab-500.ttf
------ RobotoSlab-600.ttf
- In fontDB.js edit the JS array of object named db according to your fonts which contains details about the fonts in the /fonts folder. For eg:
const db = [
{
family : "RobotoSlab",
type : "Slab Serif",
weights : [100, 200, 300, 400, 500, 600, 700, 800, 900]
},]
The db array is mainly to make the API less complex for me. I plan to use MongoDB to store the font details
Get a list of all the fonts supported. Used for the f1, f2, w1 & w2 query parameter.
curl GET "https://fontgen-sb.herokuapp.com/list-fonts"
Get a list of all the syntax highlighting themes supported by highlight.js. Used for the theme query parameter.
curl GET "https://fontgen-sb.herokuapp.com/list-themes"
Generate a paragraph
curl GET "https://fontgen-sb.herokuapp.com/para?f1=Lora&w1=700&f2=Inter&w2=400&bg=ff5e79&fg=3c3980"
Parameter | Description |
---|---|
f1 | Font Family used for the heading. Defaults to Arial |
f2 | Font Family used for the content. Defaults to Arial |
w1 | Font Weight of the heading. Defaults to 600,400 |
w2 | Font Weight of the content. Defaults to 400 |
bg | Background HEX Color without the # |
fg | Foreground HEX Color without the # |
If bg and fg are not provided then bg is transparent and fg is black
Generate a code block
curl GET "https://fontgen-sb.herokuapp.com/code?font=IBMPlexMono&theme=base16/material"
Parameter | Description |
---|---|
font | Font Family of the code |
theme | Syntax highlighting theme |