OG Image Generation
Generate 1200×630 social images server-side — no external service, no Puppeteer, no API keys. Pure SVG, served directly or converted to PNG with sharp.
Default Template — Dark Gradient
A clean dark background with title, description, accent bar, and brand name. Works for any page type.
import { createOGImageSVG } from "react-ssr-seo-toolkit/og";
const svg = createOGImageSVG({
title: "How to Build an SSR App with React",
description: "A complete guide to server-rendered React with proper SEO.",
brand: "My Blog",
accentColor: "#6366f1",
// template: "default" is the default
});
// Serve from Express:
app.get("/og/default.svg", (req, res) => {
res.type("image/svg+xml").send(svg);
});
// Dynamic endpoint with query param:
app.get("/og/:slug.svg", (req, res) => {
const page = getPageBySlug(req.params.slug);
res.type("image/svg+xml").send(
createOGImageSVG({ title: page.title, brand: "My Blog" })
);
});
// Use as og:image:
openGraph: {
images: [{ url: "https://mysite.com/og/my-post.svg", width: 1200, height: 630 }]
}Article Template — Light with Category Tag
A light background with a colored category pill, author byline, and publication date. Great for blog posts and news articles.
const svg = createOGImageSVG({
title: "Premier League Preview 2026",
description: "Everything you need to know about the upcoming season.",
template: "article",
category: "Sports",
author: "James Walker",
dateString: "May 8, 2026",
brand: "Trustix UK",
accentColor: "#e63946",
});Sports Event Template — VS Layout
A dark dramatic layout with home team vs away team, separated by a glowing divider. Pass homeTeam and awayTeam to activate the VS layout.
const svg = createOGImageSVG({
title: "Liverpool vs Arsenal",
template: "sports-event",
homeTeam: "Liverpool",
awayTeam: "Arsenal",
eventDate: "Saturday, May 15, 2026 · 17:30",
brand: "Trustix UK",
accentColor: "#ffd700",
});Convert to PNG (optional)
SVG works directly as og:image in most platforms. For maximum compatibility, convert to PNG with sharp — no headless browser needed.
import sharp from "sharp";
import { createOGImageSVG } from "react-ssr-seo-toolkit/og";
app.get("/og/:slug.png", async (req, res) => {
const page = await getPage(req.params.slug);
const svg = createOGImageSVG({
title: page.title,
description: page.excerpt,
brand: "Trustix UK",
});
const png = await sharp(Buffer.from(svg))
.resize(1200, 630)
.png()
.toBuffer();
res
.type("image/png")
.set("Cache-Control", "public, max-age=86400")
.send(png);
});sharp is an optional dependency — install separately with npm install sharp. It is not bundled with react-ssr-seo-toolkit to keep the package size minimal.
Full Options Reference
| Option | Type | Description |
|---|---|---|
title | string | Main headline (required) |
description | string? | Subtitle / description |
template | "default" | "article" | "sports-event" | Visual template |
brand | string? | Brand name shown in corner |
backgroundColor | string? | Override background color |
textColor | string? | Override text color |
accentColor | string? | Override accent / highlight color |
category | string? | Category pill (article template) |
author | string? | Author byline (article template) |
dateString | string? | Display date (article template) |
homeTeam | string? | Home team name (sports-event) |
awayTeam | string? | Away team name (sports-event) |
eventDate | string? | Event date text (sports-event) |
Features Demonstrated
No External Service
Pure SVG generation — no Cloudinary, no Vercel Edge, no API keys. Works anywhere Node.js runs.
3 Built-in Templates
Default (dark gradient), Article (light with category), Sports Event (VS layout). Each is fully customizable.
Text Wrapping
Long titles and descriptions are automatically wrapped across lines and truncated with an ellipsis if needed.
SSR-Ready
Runs on the server — generate at build time, serve dynamically, or cache with HTTP Cache-Control headers.