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

The App Router can create Open Graph (OG) tags automatically when you place a specially named image in the app directory. Use a static opengraph-image.png for a fixed design, an opengraph-image.tsx route with ImageResponse for generated artwork, or metadata.openGraph.images when an image already exists at an absolute URL. The sections below show each approach, dynamic blog-post images, alt text, dimensions, caching, limits, and fixes for common failures.

Choose the right Next.js OG-image method

Method Best for Where it lives Important behavior
Static file A logo or design that rarely changes app/opengraph-image.jpg (or another supported extension) Discovered automatically; a file in a deeper route segment overrides a higher-level file.
Generated route Titles, authors, prices, or other per-page data app/opengraph-image.tsx or a segment folder Returns an image with ImageResponse; metadata routes are cached by default.
metadata.openGraph.images An image already hosted elsewhere A page or layout metadata export Each image URL must be absolute.
generateImageMetadata Several OG variants for one segment The segment’s metadata-image files Returns variant IDs; the image function renders the selected ID.

Add a static Open Graph image

  1. Create an image in PNG, JPEG, JPG, or GIF format.
  2. Place it at app/opengraph-image.png for the whole application, or inside a route segment such as app/blog/opengraph-image.png.
  3. Optionally add app/opengraph-image.alt.txt beside the image for static alternative text.
  4. Build or run the application and inspect the generated page source for og:image, dimensions, and type.

Next.js resolves the most specific matching file. Therefore app/blog/opengraph-image.png is used for blog routes even when app/opengraph-image.png exists. Keep each asset below the documented 8 MB Open Graph-image maximum. Twitter images have a separate 5 MB maximum.

Generate an image with opengraph-image.tsx

The easiest generated-image API is ImageResponse from next/og. Export alt, size, and contentType so Next.js can emit the corresponding metadata.

import { ImageResponse } from 'next/og'

export const alt = 'About Acme'
export const size = { width: 1200, height: 630 }
export const contentType = 'image/png'

export default function Image() {
  return new ImageResponse(
    <div
      style={{
        fontSize: 128,
        background: 'white',
        width: '100%',
        height: '100%',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
      }}
    >
      About Acme
    </div>,
  )
}

The official example uses 1200 × 630 pixels, a broadly accepted OG canvas. The renderer supports flexbox and a subset of CSS properties; it does not provide arbitrary browser CSS, so do not depend on CSS Grid or unsupported effects. Put fonts and other assets where the runtime can load them, and keep the component deterministic when you want stable caching.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Create a dynamic image for every blog post

Place the metadata route in the post segment, for example app/blog/[slug]/opengraph-image.tsx. The route can read the segment parameter and render a title. In current Next.js 16 documentation, params resolves to a promise.

import { ImageResponse } from 'next/og'

type Props = {
  params: Promise<{ slug: string }>
}

export const size = { width: 1200, height: 630 }
export const contentType = 'image/png'

export default async function Image({ params }: Props) {
  const { slug } = await params
  const title = slug.replaceAll('-', ' ')

  return new ImageResponse(
    <div
      style={{
        background: '#111827',
        color: 'white',
        width: '100%',
        height: '100%',
        padding: '72px',
        display: 'flex',
        flexDirection: 'column',
        justifyContent: 'center',
      }}
    >
      <div style={{ fontSize: 34, color: '#93c5fd' }}>Itech Guides</div>
      <div style={{ fontSize: 72, fontWeight: 700 }}>{title}</div>
    </div>,
  )
}

For production titles, fetch the post record rather than deriving text from the slug. If that fetch uses dynamic APIs or uncached data, the metadata route becomes dynamic; otherwise generated metadata routes are cached by default. Decide whether freshness or cacheability matters before adding per-request data.

Set an existing image through metadata

When a CDN or image service already hosts the artwork, export metadata from the page or layout. The URL must include its scheme and host.

import type { Metadata } from 'next'

export const metadata: Metadata = {
  openGraph: {
    images: [
      {
        url: 'https://example.com/og.png',
        width: 1200,
        height: 630,
        alt: 'Example article preview',
      },
    ],
  },
}

This method does not copy the image into your repository. Ensure the host serves the file publicly, returns the correct content type, and does not require a browser-only session.

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.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Supply alt text, dimensions, and content type

Static files

Use a neighboring opengraph-image.alt.txt file when a static image needs alt text. Next.js derives image type, width, and height from the special file.

Generated files

Export all three values from the metadata-image module:

  • alt: a concise description for metadata consumers.
  • size: an object such as { width: 1200, height: 630 }.
  • contentType: the generated MIME type, for example image/png.

External files

Put alt, width, and height on each openGraph.images object. Use an absolute URL, not /images/og.png.

Generate multiple OG variants

Use generateImageMetadata when one segment needs several images, such as light and dark designs or language-specific cards. Return one object per variant with an id, alt, size, and contentType; the default image function receives the selected ID and can branch on it. Keep IDs stable so cached URLs do not change unexpectedly.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Verify the result before sharing a URL

  1. Run a production build, because metadata behavior can differ from development.
  2. Open the rendered HTML and confirm og:image, og:image:alt, og:image:width, and og:image:height where applicable.
  3. Request the image URL directly. It should return the declared content type and a 200 response without authentication.
  4. Check the final byte size against the 8 MB OG limit (and 5 MB Twitter limit when the same asset is used there).
  5. Test a nested route to confirm the intended segment-specific image wins.

Troubleshoot common failures

No og:image tag appears

Check spelling and location: the convention is exactly opengraph-image in the app tree. Confirm you are using the App Router and that a nearer route segment is not shadowing the file with another metadata definition.

The wrong image is selected

Look for a more specific opengraph-image file or an openGraph.images export in the page or layout. The more specific segment takes precedence; remove or update the competing definition.

Generated image returns an error

Reduce the component to supported flexbox styles, valid JSX, and serializable values. Unsupported CSS, unavailable fonts, or code that only works in a browser can fail inside the image renderer.

Dynamic titles never update

A cached route can continue serving an earlier result. Review whether the function uses cached data, Dynamic APIs, or uncached fetches, and choose an explicit caching strategy that matches your update requirements.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Social services show a blank preview

Request the generated URL directly and inspect status, content type, redirects, and size. Remove authentication, avoid expiring URLs, and ensure the response completes within the crawler’s time budget.

External URL is rejected

Replace relative paths with a complete https:// URL and verify that the host is reachable without cookies or a login.

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 you need a reliable screenshot of a rendered page rather than a hand-built metadata graphic, ScreenshotNeo provides a single HTTP request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status.

API documentation: https://screenshotneo.com/docs/

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo also includes an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Free accounts include 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

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

Performance, reliability, and cost decisions

  • Prefer static files when the artwork is unchanged: there is no per-request data fetch and the result is straightforward to cache.
  • Use generated routes for personalized cards, but cache stable post data and avoid unnecessary remote work in the image function.
  • Keep dimensions and output type consistent across variants so crawlers and social previews behave predictably.
  • Test cold and warm requests in production; a successful local render does not prove that a social crawler can reach every dependency.
  • For external images, monitor the host’s availability and URL permanence because Next.js only records the reference.

Frequently Asked Questions

Can I use both a static file and metadata.openGraph.images?

Yes, but define an intentional precedence strategy. A route-segment image is automatically discovered, while explicit metadata can add or override images; inspect the rendered head to confirm the final result.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

What dimensions should an OG image use?

The documented Next.js ImageResponse example uses 1200 × 630 pixels. Use that size unless your design system has a specific, tested reason to differ.

Does an OG image route run in the browser?

No. It runs in Next.js’s metadata-image environment, so browser-only APIs and unsupported CSS are unsuitable.

How do I make a post image change immediately after editing content?

Ensure the image function is not relying solely on cached data. Dynamic APIs or uncached data make the metadata route dynamic; otherwise configure a cache or revalidation approach appropriate to your deployment.

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.