og-images
SKILL.md
Creating Share Images for Next.js
Generate dynamic OpenGraph (1200x630) and Twitter (1200x600) images using next/og ImageResponse.
Choosing an Approach
- File-based route (
app/opengraph-image.tsx): Best for static pages with known titles at build time. Exportruntime,alt,size,contentType, and a defaultImagefunction. - API route (
app/api/og/route.tsx): Best for dynamic content (blog posts, CMS). Acceptslugand/ortitleas query params. Reference in metadata viagenerateMetadata().
Use export const runtime = "edge" for both approaches.
File Naming Convention
| File | Purpose | Dimensions |
|---|---|---|
opengraph-image.tsx |
Facebook, LinkedIn, iMessage | 1200x630 |
twitter-image.tsx |
Twitter/X cards | 1200x600 |
app/api/og/route.tsx |
Dynamic API route | 1200x630 |