From 2b9e425c986a4e5ebc47c1403cc908512531b843 Mon Sep 17 00:00:00 2001 From: svemagie <869694+svemagie@users.noreply.github.com> Date: Tue, 31 Mar 2026 20:45:13 +0200 Subject: [PATCH] fix: og image with resvg client --- lib/og.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/og.js b/lib/og.js index a682cce..9631975 100644 --- a/lib/og.js +++ b/lib/og.js @@ -8,7 +8,7 @@ */ import satori from "satori"; -import { Resvg } from "@resvg/resvg-js"; +import { spawnSync } from "node:child_process"; import { readFileSync, writeFileSync, @@ -482,12 +482,20 @@ export async function generateOgImages(contentDir, cacheDir, siteName, batchSize const card = buildCard(title, description, date, postType, siteName); const svg = await satori(card, { width: WIDTH, height: HEIGHT, fonts }); - const resvg = new Resvg(svg, { - fitTo: { mode: "width", value: WIDTH }, - }); - const pngBuffer = resvg.render().asPng(); - - writeFileSync(join(ogDir, `${slug}.png`), pngBuffer); + // Render SVG to PNG using the system resvg CLI + // Requires: pkg install resvg + const outPath = join(ogDir, `${slug}.png`); + const resvgProc = spawnSync( + "resvg", + ["-w", String(WIDTH), "-b", COLORS.bg, "-o", outPath, "-"], + { input: svg, encoding: "buffer" } + ); + if (resvgProc.error) { + throw resvgProc.error; + } + if (resvgProc.status !== 0) { + throw new Error(`resvg CLI failed: ${resvgProc.stderr?.toString()}`); + } newManifest[slug] = { title: slug, hash }; generated++;