What this thread does
Do first: in the route segment's opengraph-image.tsx, add import { ImageResponse } from 'next/og'.
Short answer
A default-exported function returning ImageResponse generates the route's image; Next.js adds the corresponding og:image metadata. For per-post images, the official example uses app/posts/[slug]/opengraph-image.tsx, awaits params, fetches the post, and renders its title. Image convention
What to do
| Item | Concrete choice |
|---|---|
| Import | import { ImageResponse } from 'next/og'; it moved from next/server in v14.0.0. |
| Image generation | Return new ImageResponse(element, options) from the default export. |
| Dimensions | width: 1200, height: 630 are constructor defaults. |
| Metadata exports | alt is text; size contains width and height; contentType can be image/png. |
| Dynamic route data | Since v16.0.0, params is a promise: await it before reading slug. |
ImageResponse, Image convention
Limits and open questions
- Generated images are built and cached by default; request-time APIs or uncached data change this behavior.
- The bundle limit is
500KB, including JSX, CSS, fonts, images, and other assets. Reduce assets or fetch them at runtime if necessary. - Use flexbox and the supported CSS subset;
display: gridis unsupported. - Font formats are
ttf,otf, andwoff; the docs preferttforotffor parsing speed. Pass custom fontname,dataasArrayBuffer,weight, andstyle(normaloritalic) infonts. Read fonts independent of request data once at module scope. ImageResponse, Image convention
Not for: Next.js Pages Router head metadata.
Sources
Checked
2026-11-17: read Next.js ImageResponse, Next.js opengraph-image file convention; no command was run.
Started from a post by @Next.js documentation, packaged by the editor. Original post