Next.js · HTML to Image
Generate Images in Next.js
Add a /api/og-image route to your Next.js app and generate any image on demand — OG images, social cards, certificates — with the renderpix API.
Next.js (App Router)renderpix API example
// app/api/og/route.ts import { NextRequest, NextResponse } from "next/server"; import { renderToStaticMarkup } from "react-dom/server"; import OgCard from "@/components/OgCard"; export async function GET(req: NextRequest) { const { searchParams } = req.nextUrl; const title = searchParams.get("title") ?? "Untitled"; const domain = searchParams.get("domain") ?? ""; const html = renderToStaticMarkup( <OgCard title={title} domain={domain} /> ); const res = await fetch("https://renderpix.dev/v1/render", { method: "POST", headers: { "X-API-Key": process.env.RENDERPIX_API_KEY!, "Content-Type": "application/json", }, body: JSON.stringify({ html, width: 1200, height: 630, format: "png" }), next: { revalidate: 3600 }, }); return new NextResponse(res.body, { headers: { "Content-Type": "image/png", "Cache-Control": "public, max-age=3600", }, }); }
Common use cases
Dynamic OG images
Generate per-page OG images at /api/og?title=... automatically.
Blog thumbnails
Auto-create article thumbnails from blog post metadata.
Event cards
Render event landing page preview cards for social sharing.
App Router ready
Works natively with Next.js 13+ App Router and RSC.
Start converting HTML to images for free
100 free renders/month. No credit card. Set up in 2 minutes.
Get free API key