imgrender

Custom fonts

How to use custom fonts in a request

imgrender includes fonts that are free for commercial use. Prefer the built-in fonts, which render faster.

Which API this applies to

This page explains how to pass custom fonts in the request body of the Generate image from HTML API.

If you use the recommended Generate image from template API, configure fonts on the template in the template editor. You do not need to pass fonts in the request.

The following explains how to use custom fonts in a request.

Load custom web fonts

If your design needs a special font file, you can dynamically register custom fonts with the fonts array field in the request body.

In the fonts array, you can pass objects with the following structure:

FieldTypeRequiredDescription
familyNamestringyesFont family name. Only English letters (uppercase or lowercase) and digits are allowed. In content, reference this name with fontFamily, and the match must be exact.
fontUrlsstring[]yesList of URLs to download the font files. Common formats such as TTF, OTF, and WOFF are supported.

Notes:

The familyName property overrides the font name in the font file metadata, but properties such as weight and style still come directly from the font file metadata. Each object therefore corresponds to one font family. Every font file listed in its fontUrls should belong to that family, and each weight and style should be unique.

Example:

{
    "content": ,
    fonts: [
        {
            "fontFamily": "MyFont1",
            "fontUrls": [
                "https://example.com/MyFont1/Regular.ttf",
                "https://example.com/MyFont1/Medium.ttf",
                "https://example.com/MyFont1/SemiBold.ttf",
                ...
            ]
        },
        {
            "fontFamily": "MyFont2",
            "fontUrls": [
                "https://example.com/MyFont2/Regular.ttf",
                "https://example.com/MyFont2/Medium.ttf",
                "https://example.com/MyFont2/SemiBold.ttf",
                ...
            ]
        }
    ]
}

On-demand font loading

imgrender downloads and loads a custom font only when content actually references that font's familyName through fontFamily. Fonts that are not referenced are not loaded.

See How to use fonts.

Requirements for fast font loading

  1. Keep font files as small as possible. They must not exceed 10 MB. Files larger than 10 MB fail to load.

  2. Make sure the URL is reachable on the public internet. If the service hosting your font has authentication enabled (for example, a private object storage service), the font URL must include the authentication information.

  3. The URL must load quickly over the public internet.

On this page