All topics

How to Generate Dynamic OG Images for Every Page

Manually creating an OG image for every blog post or product page does not scale. Once you have more than a handful of pages, you need a system that generates unique, branded social preview images automatically. There are several approaches, each with different tradeoffs around performance, cost, and visual quality.

Why Static OG Images Fall Short

Most websites start by creating a single OG image and reusing it across every page. This works initially but creates a poor experience when users share different pages and they all show the same generic preview. Unique OG images per page dramatically improve click-through rates because they give the viewer context about what specific content they will find. For content-heavy sites like blogs, documentation, or e-commerce stores, each page represents a different topic or product, and the social preview should reflect that. The challenge is creating hundreds or thousands of unique images without a design team manually producing each one.

Template-Based Server-Side Generation

The most common approach to dynamic OG images is rendering HTML/CSS templates to images on the server. Tools like Satori (used by Vercel's @vercel/og) convert JSX components into SVGs, which are then rasterized to PNG. You define a template with your brand colors, logo, and typography, then inject the page title and description at request time. This approach runs at the edge or on your server and produces consistent, branded images quickly. The limitation is that you are constrained to basic layouts and the subset of CSS that the rendering engine supports, which means complex designs or photographic backgrounds are difficult to achieve.

API-Based Image Generation Services

External services provide APIs where you send parameters like text, colors, and layout options, and they return a generated image. This offloads the rendering work and often provides more design flexibility than self-hosted solutions. The tradeoff is latency (an external API call adds 200-500ms) and cost (most services charge per image). Caching is essential with this approach, so you generate each image once and serve it from your CDN for subsequent requests. Services like OGImagen take this further by using AI to create visually compelling backgrounds and compositions that go beyond simple text-on-color templates.

AI-Powered OG Image Generation

The newest approach uses AI image generation models to create unique, visually rich OG images that look like they were designed by a professional. Instead of placing text on a flat color or gradient background, AI can generate contextual illustrations, abstract art, or themed visuals that match your content. The text overlay, branding, and layout are then composited on top. This produces images that stand out in crowded social feeds where most OG images look like the same template with different words. The processing time is longer than template-based approaches (a few seconds versus milliseconds), but with proper caching and async generation, the user experience remains smooth.

Caching and Performance Strategy

Regardless of your generation method, you should never generate the same OG image twice. Use a CDN like Cloudflare R2, AWS CloudFront, or Vercel Edge Cache to store generated images with long cache TTLs. A common pattern is to generate images on first request and cache them permanently, or to generate them as part of your build or publish pipeline. For sites using ISR (Incremental Static Regeneration) in Next.js, you can generate OG images during the revalidation step. Set appropriate Cache-Control headers so that social platform crawlers and CDN nodes serve cached versions. Include a cache-busting parameter in the image URL when content changes so stale images get replaced.

Generate your OG image in seconds

Paste a title, pick a brand color, and get production-ready social cards for every platform — with framework-specific meta tag snippets included.

Try AI-Powered OG Image Generation