research/og-images-from-the-page-component
Generating Open Graph Images From the Same Component That Renders the Page
Engineering Note · November 16, 2026 · 8 minute read · Open Graph · React · Satori · Fonts
You can keep the share image and the page in step by rendering one React component two ways: into the page with react-dom/server, and into a 1200 by 630 PNG with Satori and resvg. We did that with a small title card. The image matched a Chromium screenshot of the same component closely, once we fixed one font problem. The self-hosted font files were variable fonts, and Satori draws a variable font at its default weight, which for one of ours was 300 instead of the 500 we wanted. Pinning each font to a static weight brought the two images within 2% of their pixels.
Everything below was run with Node.js 22.23.4, React and React DOM 19.3.1, Satori 0.63.2, @resvg/resvg-js 2.6.2, Playwright 1.63.0 with Chromium 153.0.8010.12 (headless), and fontTools 4.68.0 on Python 3, on Linux with 4 CPUs. The outputs are the real ones from this run.
What problem does this solve?
An Open Graph image is the picture a chat app or social network shows when someone shares a link. The page names it with <meta property="og:image">, usually at 1200 by 630 pixels.
When those images are made by hand, they drift. The page title changes and the share image keeps the old one. A new post goes out with no image, or with the generic site logo. If the image is drawn by the same component that draws the title card on the page, a title change updates both.
What does the component look like?
Plain markup and inline styles, nothing else. We wrote it with createElement so it runs in Node without a JSX build step:
import { createElement as h } from 'react';
// One component, two outputs: the card at the top of the page, and the 1200x630 share image.
export function ShareCard({ title, section, date }) {
return h('div', { style: {
width: 1200, height: 630, display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
padding: 72, background: '#0f1b2d', color: '#f4f1ea', fontFamily: 'Inter', boxSizing: 'border-box' } },
h('div', { style: { display: 'flex', fontSize: 28, letterSpacing: 2, color: '#e8b04b', textTransform: 'uppercase' } }, section),
h('div', { style: { display: 'flex', fontFamily: 'Space Grotesk', fontSize: 64, lineHeight: 1.1 } }, title),
h('div', { style: { display: 'flex', justifyContent: 'space-between', fontSize: 26, color: '#b8c2d1' } },
h('span', null, 'GVX Digital'), h('span', null, date)));
}
On the page, the component goes through renderToStaticMarkup like any other. For the image, it goes through Satori, which lays out React elements and writes an SVG, and then resvg, which turns the SVG into a PNG:
import satori from 'satori';
import { Resvg } from '@resvg/resvg-js';
import fs from 'node:fs';
import { ShareCard } from './ShareCard.mjs';
const ext = process.argv[2] || 'ttf';
const fonts = [
{ name: 'Inter', data: fs.readFileSync(`inter-normal-400.${ext}`), weight: 400 },
{ name: 'Space Grotesk', data: fs.readFileSync(`space-grotesk-normal-500.${ext}`), weight: 500 },
];
const props = { title: 'Lazy-Loaded Images That Do Not Shift the Layout', section: 'Engineering Note', date: 'Nov 16, 2026' };
const svg = await satori(ShareCard(props), { width: 1200, height: 630, fonts });
const png = new Resvg(svg, { fitTo: { mode: 'width', value: 1200 } }).render().asPng();
fs.writeFileSync('og.png', png);
Satori needs the font data passed in. It does not read @font-face rules or fetch anything. We used two files copied from our own site’s self-hosted fonts folder.
Does Satori take WOFF2 files?
Our fonts are WOFF2, the compressed web format. We expected to have to convert them. We converted copies to TTF with fontTools anyway and rendered both ways:
== woff2
svg 35829 chars in 81 ms; png 32395 bytes in 53 ms
png size 1200 x 630
== ttf
svg 35829 chars in 63 ms; png 32395 bytes in 59 ms
png size 1200 x 630
Then we hashed each output:
$ node og.mjs woff2 >/dev/null && md5sum og.png
67b94ac8f9e27a876949d1f43fd45913 og.png
$ node og.mjs ttf >/dev/null && md5sum og.png
67b94ac8f9e27a876949d1f43fd45913 og.png
The PNGs were byte-for-byte identical. The README shipped in the Satori 0.63.2 package lists TTF, OTF, WOFF and WOFF2 as supported. We did not check older versions.
How close is it to what the browser draws?
We put the same component in a page with @font-face rules for the same two WOFF2 files, took a 1200 by 630 Chromium screenshot, and compared the two PNGs pixel by pixel in a canvas:
chromium 153.0.8010.12 screenshot 35423 bytes in 35 ms
{"differing":24609,"over64":18320,"total":756000} 3.26% of pixels differ, 2.42% by more than 64/255
Laid side by side, the layout matched, but the title in the Satori image was visibly thinner. That was the font trap.
Why was the weight wrong?
We asked fontTools what was inside the two files:
inter-normal-400 [('wght', 100.0, 400.0, 900.0)] usWeightClass 400
space-grotesk-normal-500 [('wght', 300.0, 300.0, 700.0)] usWeightClass 300
Both are variable fonts: one file that covers a range of weights on a wght axis. The file names say 400 and 500, but Space Grotesk’s default point on the axis is 300.
The browser was told, through @font-face, that this face is weight 500, so it drew the title at 500. Satori’s README says variable fonts are drawn at their default instance. So Satori drew 300, even though we registered the font with weight: 500. Inter happened to work because its default is 400, the weight we wanted.
A file name is not a promise about what is inside. When we self-hosted our Google Fonts, variable families came back as one file that every weight points at. That is the right file for the page and the wrong input for Satori.
How do we pin a variable font to one weight?
fontTools can cut a static instance out of a variable font:
from fontTools.ttLib import TTFont
from fontTools.varLib import instancer
for name, w in [('space-grotesk-normal-500', 500), ('inter-normal-400', 400)]:
t = TTFont(name + '.woff2')
s = instancer.instantiateVariableFont(t, {'wght': w})
s.flavor = None
s.save(name + '.ttf')
space-grotesk-normal-500 -> static wght 500 False
inter-normal-400 -> static wght 400 False
(False is the answer to “does it still have a variable-font table?”) We rendered again with the pinned files and repeated the comparison:
svg 35901 chars in 67 ms; png 32545 bytes in 46 ms
png size 1200 x 630
chromium 153.0.8010.12 screenshot 35423 bytes in 32 ms
{"differing":14742,"over64":7146,"total":756000} 1.95% of pixels differ, 0.95% by more than 64/255
Pixels that differ by more than a quarter of the brightness range fell from 2.42% to 0.95%. By eye the title weight now matched. We did not trace the remaining difference, so we will not say where it comes from. Two different text renderers are unlikely to agree on every edge pixel.
Run the pinning once when fonts change and commit the static files next to the build script. The page keeps using the variable WOFF2 files.
What does the component have to avoid?
We tried a few things that commonly appear in page components:
display: table: threw: Invalid value for CSS property "display". Allowed values: "block" | "flow-root" | "list-item" | "flex" | "-webkit-flex" | "-webkit-box" | "grid" | "in
component using useState: threw: Cannot read properties of null (reading 'useState')
misspelled value (justifyContent: "centre"): threw: Invalid value for CSS property "justifyContent". Allowed values: "center" | "start" | "end" | "left" | "right" | "flex-start" | "flex-end" | "stretch"
Grid, block layout, a className without a stylesheet, and a bold weight with only a regular font registered all rendered without an error. So keep the shared component simple:
- No hooks. Satori renders once, with no React runtime state. Pass everything in as props.
- Valid inline style values. A typo throws and fails the whole render. That is better than a silent wrong image, as long as the build stops on it.
- No
display: table. It throws. - Fonts passed in explicitly, pinned to the weights the component uses.
Is it faster than a browser screenshot?
We rendered 50 cards each way, twice. The Chromium time includes launching the browser:
satori+resvg: 50 images in 2.34 s
chromium screenshots (incl. launch): 50 images in 2.46 s
satori+resvg: 50 images in 2.43 s
chromium screenshots (incl. launch): 50 images in 2.62 s
About the same. The real difference is what each one needs. Satori and resvg are npm packages with no browser. The screenshot route needs a Chromium binary wherever the build runs, and matches the page exactly because it is the page. Pick by where your build runs.
Limitations
- One component, one title length and two fonts. We did not test long titles that overflow, emoji, right-to-left text or images inside the card.
- The comparison is against headless Chromium on Linux. Other browsers and operating systems draw text differently.
- Timings are from one 4-CPU Linux container. They tell you the two methods are close here, nothing more.
- We did not wire this into an Astro build or deploy it. The test ran as standalone Node scripts.
- The claim that Satori draws variable fonts at their default instance comes from its README; our test matched it for one font.
Related reading
- Self-hosting Google Fonts without a build plugin
- Typed content collections in Astro for a research section
- Lazy-loaded images that do not shift the layout
Frequently asked questions
What is an Open Graph image?
It is the picture shown when someone shares a link in a chat app or on social media. A page names it with an og:image meta tag, usually at 1200 by 630 pixels. Making one per page by hand does not scale, so most sites generate them.
Can I use the same React component for the page and the og:image?
Yes, if the component is plain markup and inline styles. Satori turns React elements into an SVG, and resvg turns that into a PNG. In our test, Satori 0.63.2 rendered the same component we rendered with react-dom/server. A component that called useState failed, so keep hooks out of it.
Why does my Satori image use the wrong font weight?
Check whether your font file is a variable font. Satori's README says variable fonts are drawn at their default instance. Our Space Grotesk file was named for weight 500 but its default was 300, so Satori drew it light while the browser drew 500. Pinning the file to weight 500 with fontTools fixed it.
Does Satori accept WOFF2 fonts?
Version 0.63.2 did in our test. The PNG rendered from our WOFF2 files was byte-for-byte identical to the one from TTF copies of the same fonts. The package README lists TTF, OTF, WOFF and WOFF2.
Is Satori faster than taking a browser screenshot?
Not by much in our test. Fifty images took about 2.3 to 2.4 seconds with Satori and resvg, and about 2.5 to 2.6 seconds with Chromium screenshots, including the browser launch. Choose by where the code has to run, not by speed.