Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Automatically generated Open Graph (OG) images let each page have a relevant link-preview image without designing a separate file by hand. The three practical patterns are to render a card from HTML/CSS on demand, transform a reusable image template, or capture a rendered HTML page in a headless browser. The right choice depends on how complex your layout is, what services your site already uses, and which part of the rendering pipeline you want to operate.

What an automatically generated OG image needs

An OG image is the visual card a social or messaging platform may show when someone shares a page. Automation means generating or selecting that image from page-specific data—such as a post title, description, author, or product image—rather than preparing a different image manually for every URL.

There are two separate jobs: create an image, and make the page advertise that image in metadata that a crawler can fetch. Generating a file alone does not guarantee that a preview will use it. The page needs appropriate metadata, and the image URL must be publicly accessible to the relevant crawler.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Vercel recommends 1200 × 630 pixels for OG images. Treat that as a recommendation from Vercel, not a universal requirement for every destination platform. Its preview documentation says the twitter:image field accepts a URL to a static or dynamically generated image and lists JPG, PNG, WEBP, and GIF as supported formats for that field; SVG is not supported there. It also describes og:image as a fallback for Twitter image metadata, and og:title and og:description as fallbacks for Twitter title and description. Vercel’s OG image-generation documentation and its metadata preview documentation explain the relevant setup.

1. Render HTML and CSS into an image on demand

If your site can serve a dynamic image endpoint, define the card as code and pass the page’s content into it. A route can receive a title and other values, render the design, and return an image. This is a natural fit for teams that want layouts maintained alongside application code, particularly when the project already uses Next.js and Vercel.

Vercel’s documented @vercel/og approach uses Satori and Resvg to convert HTML and CSS into PNG. Its examples include dynamic titles and external images, and the documentation describes CDN caching headers for computed images. See the current implementation documentation and official examples for exact APIs and version-sensitive setup.

Implementation constraints to check

  • The documented setup requires Node.js 22 or newer and Next.js 12.2.3 or newer; the Next.js App Router includes the package. Verify the current requirements when setting up, since framework guidance can change.
  • The renderer supports a subset of CSS. Flexbox is supported; CSS Grid is not. A design that depends on grid may need to be rewritten or implemented with another approach.
  • Font files are limited to TTF, OTF, and WOFF formats.
  • The documented bundle limit is 500 KB. This is a limit for the described renderer bundle, not a recommended output image-file size.
  • Vercel notes a response-syntax limitation for a Pages Router plus Node.js configuration. Check the current docs if that describes your application.
  • Vercel recommends allowing OG image routes in robots.txt so sharing crawlers can fetch them.

Before adopting this route, prototype the longest title, a title in each language you support, and any external image or font loading the design needs. That exposes clipping and unsupported styles before the endpoint is used across the site. Vercel’s example gallery is a useful reference for patterns, but its examples are not a guarantee that arbitrary HTML or CSS will render unchanged.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Transform a reusable image template

If your card design is mostly a background image plus text and a few graphic elements, a hosted image transformation service can generate variations from one reusable source. A URL specifies operations such as resizing, cropping, text overlays, or adding graphics. Your application supplies page-specific values, such as the article title and description, while the service returns the transformed image.

Cloudinary’s Astro walkthrough demonstrates a shared template with distinct OG images generated from each post’s title and description. Its overview also lists resizing, cropping, overlays, and graphical elements among the supported transformation patterns. See Cloudinary’s overview of dynamic social images and its Astro and Cloudinary tutorial.

Check the template against real content

  • Test long titles, punctuation, and the languages your site publishes. A text overlay that works for a short English headline may overflow or become hard to read with longer text.
  • Consider whether the service already stores the source assets you need. A transformation workflow is more direct when your base image and related graphics are already available there.
  • Plan how the transformation URL is assembled, delivered, and updated when page data changes. Avoid exposing untrusted input as arbitrary transformation instructions; define the operations your application permits.
  • Confirm that the resulting image URL is stable and reachable by the crawlers that read your metadata.

This approach is most suitable when the desired design maps cleanly to a reusable image and a defined set of overlays. The cited Cloudinary material describes capabilities and an example workflow; it does not establish an independent comparison of provider pricing or performance.

3. Capture an HTML page or template in a headless browser

A headless browser loads a web page or standalone HTML template, renders it, and captures the result as an image. Use this pattern when your card depends on browser-rendered HTML that does not fit a specialized renderer’s supported subset, or when reusing a page layout is more practical than translating it into image transformations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cloudinary’s overview describes headless-browser capture as one way to generate images from page content. Browser rendering also means operating or using infrastructure that loads pages and captures them; that additional operational responsibility is an implementation trade-off, not a measured performance or cost comparison. The workflow needs to account for fonts and assets loading, viewport dimensions, capture timing, and the handling of pages that fail to render. If a capture takes place in a build process, also decide how failures affect that build.

When custom image code is a better fit

Cloudinary also lists server-side or build-time scripts using image-processing libraries such as Sharp or Canvas. This can suit teams that want control over the rendering pipeline without capturing a browser page. It requires the team to implement and maintain the card layout and image composition directly. The cited material identifies this as an option but does not provide a neutral benchmark against the other methods.

How to choose among the approaches

Approach Best fit What you operate Main consideration
HTML/CSS image endpoint Code-defined cards with page-specific data, especially in a compatible Next.js/Vercel setup A dynamic image route and its deployment/runtime Renderer CSS, font, bundle, and runtime constraints
Reusable image transformations A consistent branded template built from a base image plus text or graphic overlays Transformation URLs and the source assets Long or localized text must fit the template; provider pricing and performance are not established by the cited walkthrough
Headless-browser capture Cards that rely on browser-rendered HTML or a page/template you want to capture Browser-rendering infrastructure or a service that provides it Rendering and capture infrastructure adds operational work; no measured cross-method cost or speed comparison is established
Custom Sharp or Canvas scripts A team that wants direct control of image composition in server-side or build-time code The image-generation script and its execution environment Layout and rendering behavior become your implementation to maintain

These are decision criteria based on the documented workflows, not a claim that one option is universally fastest, cheapest, or best. Start with your existing stack, the complexity of the card, and how much rendering infrastructure you want to own. Vercel’s 2022 announcement claimed its approach was 5× faster than existing solutions, but that is a historical vendor comparison, not an independent benchmark; it should not be used as a general performance guarantee. The announcement is dated October 10, 2022.

Publish metadata that points to the generated image

Whichever generation method you choose, emit metadata on the page being shared. An illustrative pair of fields is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<meta property="og:image" content="https://example.com/og/article-slug.png">
<meta name="twitter:image" content="https://example.com/og/article-slug.png">

Replace the example URL with the actual absolute, publicly fetchable image URL for that page. Your application should also provide the page’s appropriate title and description metadata. Vercel’s preview documentation explains its described fallbacks between OG and Twitter fields; destinations and crawlers can differ, so inspect the metadata and preview for the platforms you care about rather than assuming one generated file is sufficient. Vercel’s metadata documentation describes its preview guidance.

For a Vercel-generated route, allow crawlers to reach that route in robots.txt, as Vercel recommends. More generally, ensure the page and image do not require a logged-in session or a browser-only state unavailable to the crawler. If a preview is stale, the reviewed sources do not establish one cache-invalidation procedure that works across platforms; cache behavior and refresh rules vary by destination.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your chosen approach involves capturing a rendered page, ScreenshotNeo can return a screenshot or PDF with one GET request. Its screenshot API can render the HTML page or template you use for a card; you still need to set up the OG metadata on your page and ensure the image URL is accessible to crawlers. See the ScreenshotNeo website and API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/og-template?title=Hello -o shot.webp

Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; each cleanup step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers indicating the page verdict and billing status. ScreenshotNeo also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sign up for ScreenshotNeo’s free plan to try the capture API without a card.

Troubleshooting generated OG previews

The image is missing or the preview uses a different image

  • Inspect the page’s rendered source and verify that og:image contains the intended absolute URL. Check any Twitter image metadata as well.
  • Open the image URL without being logged in. Check for redirects, access controls, or a route that only works when a browser session is already established.
  • Confirm the image-generation route is permitted for crawlers by your robots.txt, particularly if you use Vercel’s route approach.
  • Use the relevant platform’s preview inspection tool to see what metadata it reads. Vercel also documents preview inspection for OG metadata.

The card has clipped text or broken styling

  • Test the longest supported title and descriptions, then adjust font size, line wrapping, or the card’s text area.
  • For @vercel/og, check whether the layout uses unsupported CSS such as Grid, whether the font is a supported file format, and whether the documented bundle limit is exceeded.
  • For a transformation template, validate the overlay position and text handling with long and localized values before using it for every page.

The captured image is blank or incomplete

  • For browser-based capture, check whether the page itself renders correctly at the target viewport, and whether fonts, images, or scripts have loaded before capture.
  • For any on-demand route, inspect the route response and server logs for rendering or asset-loading failures; a metadata tag cannot make a failed image endpoint work.
  • Check whether the image URL is cached by your generation or delivery layer. Platform preview caching is destination-specific, and the sources do not establish a universal refresh sequence.

FAQ

Does generating an OG image guarantee that every site shows it?

No. The page must publish correct metadata, the image must be fetchable, and the destination must successfully process the page. Preview behavior and cache refresh vary by platform.

Can I use the same image URL for Open Graph and Twitter metadata?

Vercel’s documentation describes og:image as a fallback for Twitter image metadata, but its guidance is not a guarantee about every crawler. Supplying the fields explicitly and checking the destination preview makes the intended image clearer.

Is 1200 × 630 mandatory?

No universal requirement is established here. It is the size Vercel recommends for OG images; check the current guidance for the platforms and formats you target.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.