Factory function to create a new TemplateRenderer instance.
Function Signature
function createRenderer <
TMap extends Record < string , OgTemplateParams > = Record <
string ,
OgTemplateParams
>
>( config : OgTemplateRenderer < TMap >) : TemplateRenderer < TMap >;
Parameters
config
OgTemplateRenderer<TMap>
required
Handler configuration with templates and global settings A map of template objects, keyed by a unique string ID
Default parameters that will be applied to all templates. Useful for brand consistency. Can be an object or a function returning a Promise. User-provided parameters take precedence over shared parameters during rendering.
Caching configuration for fonts and icons. If not provided, defaults to in-memory caching with { type: 'memory' } Cache type. Defaults to 'memory' if not specified
Time to live in milliseconds. Default: No expiration
Maximum number of items in cache. Default: 100
Directory for filesystem cache (required if type is 'filesystem')
Hook called before rendering ( templateId : string , params : any ) => void | Promise < void >
Hook called after rendering ( templateId : string , params : any , buffer : Buffer ) => void | Promise < void >
Returns
The renderer instance with methods for managing templates and generating
images
Examples
Basic Usage
With Caching
With Hooks
import { createRenderer } from "@ogify/core" ;
import basicTemplate from "@ogify/templates/basic" ;
import type { TemplateParams } from "@ogify/templates/basic" ;
const renderer = createRenderer <{ basic : TemplateParams }>({
templates: { basic: basicTemplate },
sharedParams: {
brandName: "My Company" ,
brandLogo: "https://example.com/logo.png" ,
},
});