This repository has no description
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344import 'server-only'import { readFile } from 'node:fs/promises'import path from 'node:path'
let kronaFont: ArrayBuffer | undefinedasync function font() { if (!kronaFont) { const buf = await readFile(path.resolve('public/fonts/KronaOne-Regular.ttf')) kronaFont = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength) as ArrayBuffer } return kronaFont}
let wasmInitialized = falseasync function ensureResvg() { const mod = await import('@resvg/resvg-wasm') if (!wasmInitialized) { // The wasm binary ships in the package; init once. const wasmBuffer = await readFile( path.resolve('node_modules/@resvg/resvg-wasm/index_bg.wasm'), ) await mod.initWasm(wasmBuffer) wasmInitialized = true } return mod}
export async function renderOgPng(node: import('react').ReactElement) { const { default: satori } = await import('satori') const { Resvg } = await ensureResvg() const svg = await satori(node, { width: 1200, height: 630, fonts: [{ name: 'Krona One', data: await font(), weight: 400, style: 'normal' }], }) const png = new Resvg(svg).render().asPng() return new Response(png, { headers: { 'content-type': 'image/png', 'cache-control': 'public, max-age=31536000, immutable', }, })}