Skip to main content
The main class for managing templates and rendering images. Typically created via createRenderer(), but can be instantiated directly if needed.
For complete type definitions and interfaces, see the Type Definitions page.

Methods

getTemplate

Retrieves a template by its unique ID.

Parameters

id
string
required
The template ID to look up

Returns

template
OgTemplate | undefined
The template definition, or undefined if not found

renderToImage

Renders a template to a PNG image buffer. This is the main method for generating OG images.

Parameters

templateId
string
required
The ID of the template to render
params
object | function
required
Parameters specific to the chosen template, or a function returning a Promise of parameters. User-provided parameters override shared parameters.
options
OgTemplateOptions
Rendering options

Returns

buffer
Promise<Buffer>
A promise that resolves to the PNG image buffer

Rendering process

1

Template Lookup

Looks up the template by ID in the internal registry
2

Parameter Merging

Merges shared params with user paramsPriority: Parameters are merged with the following precedence (highest to lowest):
  1. params passed to renderToImage()
  2. sharedParams from renderer configuration
  3. Template default parameters
3

Cache Checking

Generates a cache key and checks for a cached PNG buffer
4

Inflight Deduplication

If an identical render is already in progress, returns the shared in-flight promise instead of starting a duplicate render
5

Before Render Hook

Calls beforeRender hook if configured
6

Core Rendering

Delegates to the core rendering engine
7

Cache Storage

Caches the generated image
8

After Render Hook

Calls afterRender hook if configured
9

Return Buffer

Returns the PNG buffer

Examples

Usage Example