Q43: How does ImageResponse (next/og) generate dynamic Open Graph images?
ImageResponse uses Satori and Resvg under the hood to convert JSX flexbox code into PNG social share images dynamically at the Edge, eliminating external graphic editor pipelines.
Dynamic OG Image Generation Route
// app/api/og/route.js
import { ImageResponse } from 'next/og';
export async function GET(request) {
const { searchParams } = new URL(request.url);
const title = searchParams.get('title') || 'Default Title';
return new ImageResponse(
(
<div style={{ fontSize: 60, color: 'white', background: 'black', width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
{title}
</div>
),
{ width: 1200, height: 630 }
);
}ImageResponse converts JSX layout objects into dynamic 1200x630 PNG Open Graph images.
Key Takeaways
Generates dynamic Open Graph social preview images using JSX code.
Executes at Edge runtimes using HTML/CSS Flexbox subsets.
Knowledge Check
What output format does the ImageResponse (next/og) constructor produce?