Og images

From richtabor/agent-skills · View interactive version

Og images is an AI agent skill from the GitHub repository richtabor/agent-skills. Guides creation of OpenGraph and Twitter share images using next/og ImageResponse. Covers layout patterns, custom fonts, avatars, title case, and Satori rules. Use when building OG images, Twitter cards, or social previews.

How to use this skill

Skill file

Creating Share Images for Next.js

Generate dynamic OpenGraph (1200x630) and Twitter (1200x600) images using next/og ImageResponse.

Choosing an Approach

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 |

Place file-based routes in the relevant route directory (e.g., app/about/opengraph-image.tsx for /about).

Layout Pattern

Avatar / Logo (Optional)

If the project has an avatar or logo, place it in the bottom-right corner using a flex container with justifyContent: "flex-end". Load images via fetch + arrayBuffer, convert to base64 data URI for the src. Use borderRadius: "50%" for circular avatars. Cache loaded assets in a Map to avoid refetching.

Custom Fonts

Load .ttf files from public/fonts/ using new URL("../../../public/fonts/YourFont.ttf", import.meta.url). Pass the ArrayBuffer to ImageResponse via the fonts option. Cache the font buffer after first load. Match the weight in the fonts config to the actual font file weight.

Title Case

If titles come from a CMS, apply smart title case:

Metadata Integration

Reference the OG route in generateMetadata():

export function generateMetadata({ params }) {
  return {
    openGraph: {
      images: [`/api/og?slug=${params.slug}`],
    },
  };
}

For static pages, pass the title directly: /api/og?title=About.

Satori Rules

These are hard requirements of the next/og rendering engine (Satori):

  1. Every element needs display: "flex" — this is the only layout mode
  2. Inline styles only — no CSS classes, no external stylesheets, no CSS variables
  3. All text must be in elements with explicit style props
  4. Use hex colors — no rgb(), hsl(), or CSS variables
  5. No gap on older versions — test before relying on it; fallback to margin

Common Issues

| Issue | Solution |

|-------|----------|

| Text not rendering | Add display: "flex" to the text wrapper |

| Layout broken | Ensure all containers have display: "flex" |

| Colors wrong | Use hex colors, not CSS variables |

| Font not loading | Check the relative path from route file to public/fonts/ |

| Image not showing | Convert to base64 data URI, don't use relative paths |

Testing

Preview during development by visiting the route directly in the browser:

http://localhost:3000/api/og?title=Hello+World

After building, verify routes register as dynamic (f prefix) in the build output.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.