Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk6 min

Convert HTML to PNG in a Next.js App

Use Next.js ImageResponse for controlled JSX graphics, not arbitrary browser screenshots. Learn how to return a PNG from a Route Handler and what to check before deployment.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the image can be built from JSX and the CSS supported by Next.js, use ImageResponse to generate a PNG. For a public URL that clients can fetch, put it in an App Router Route Handler. This is a generated-image renderer—not a guarantee of screenshot fidelity for arbitrary HTML and browser CSS.

Choose the right rendering path

Next.js ImageResponse uses @vercel/og, Satori, and resvg to render JSX as an image. It suits controlled graphics such as social cards, badges, and simple data-driven visuals. Its documented CSS support is limited: flexbox and a subset of properties work, while advanced layouts such as CSS Grid do not. Check the current guide for font and styling requirements for your installed Next.js version: Next.js Metadata and OG images.

As an Amazon Associate I earn from qualifying purchases.

  • Use ImageResponse when you control the markup and can express the design using its supported JSX and CSS.
  • Use a real browser-rendering approach when you need a faithful screenshot of an arbitrary page, browser-only APIs, or authenticated browser state. The Next.js ImageResponse documentation does not establish full browser screenshot fidelity.
  • Render in a client component when the task depends on interactive state or browser-only APIs. Use a server route when callers need an image endpoint. Next.js explains the distinction in its Server and Client Components guide.

Generate a PNG from JSX with ImageResponse

For a request-driven image endpoint, create app/api/card/route.ts. This example accepts a title, supplies a fallback, and returns PNG bytes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { ImageResponse } from 'next/og';

export const runtime = 'edge';

export async function GET(request: Request) {
  const { searchParams } = new URL(request.url);
  const title = searchParams.get('title') ?? 'Hello from Next.js';

  return new ImageResponse(
    (
      <div
        style={{
          width: '100%',
          height: '100%',
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'center',
          backgroundColor: '#111827',
          color: '#ffffff',
          fontSize: 56,
          fontWeight: 700,
          padding: 48,
        }}
      >
        {title}
      </div>
    ),
    { width: 1200, height: 630 },
  );
}

Save it as app/api/card/route.ts, then run the Next.js development server and request /api/card?title=Launch. The handler returns an image response; save the response body as a PNG or use the URL in a context that accepts images. The example uses flexbox rather than Grid to stay within the documented CSS subset. For the installed version’s precise API and font handling, follow the official ImageResponse guide.

Validate and protect the endpoint

Route Handlers are public endpoints unless your application adds access controls. If the image contains private or costly-to-render content, authenticate and authorize callers, validate query parameters, and avoid returning internal exception details. Route Handlers use Web Request and Response APIs and support GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS; see the Route Handlers guide.

Return a generated image from a route

The preceding handler already returns the ImageResponse directly, which is the shortest path for a generated image. Route Handlers can return image and file content. They are not cached by default; a GET route can opt into caching through route configuration. Cache only when the output is stable and safe to share—for example, do not publicly cache personalized output under a shared URL.

When caching, include every input that changes the output in the cache key or URL, and choose a policy appropriate to how quickly the underlying content changes. If results must reflect fresh user-specific data, leave shared caching off and enforce authorization.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

When ImageResponse is not enough

A browser screenshot captures a rendered page with browser layout and runtime behavior. ImageResponse instead renders a supported JSX/CSS representation. If your requirement is “turn this arbitrary existing HTML page into the same pixels a browser displays,” assess a browser-rendering implementation separately. Verify that its browser binary, filesystem needs, memory use, and execution time are supported by your deployment host; no particular third-party automation package or host configuration is established here.

For either approach, choose based on the actual requirement: CSS fidelity, browser APIs or logged-in state, deployment support for binaries and filesystem access, execution time limits, and whether images should be generated on demand or precomputed.

Deployment constraints to check

  • Serverless or lambda hosting: some hosts run handlers as lambdas. Next.js notes that requests may not share in-memory data, filesystem writes may be unavailable, and long-running work may be terminated on timeout. Check the current limits of your host before bundling a browser or relying on a long render. See Next.js Backend for Frontend.
  • Static export: a static export has no runtime server. Runtime-dependent features are unsupported; only statically configured GET Route Handlers are supported in export mode. A request-time image that depends on input or live data therefore needs a runtime deployment rather than a static-only export. See the deployment guidance.
  • Timeouts and load: keep request-time work within the host’s execution limits. For slow or expensive generation, consider precomputing stable images or using an asynchronous architecture supported by your stack.
  • Shared data and caching: do not assume a handler’s in-memory state persists across requests or instances. Make caching decisions based on whether output is stable and safe to share.

Troubleshoot common problems

The image does not match the page in a browser

ImageResponse is not a full browser screenshot renderer. Recreate the design in supported JSX/CSS or choose a browser-rendering path when arbitrary page fidelity is required.

Grid or another style is missing

Check the supported CSS list for your installed Next.js version. The documented renderer supports flexbox and a subset of CSS properties; advanced layouts such as display: grid will not work. Simplify the layout using supported styles.

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

The route works locally but fails after deployment

Check whether the host supports the chosen runtime and all required files or binaries, whether filesystem writes are allowed, and whether the handler exceeds a duration limit. Those constraints vary by host; consult its current deployment documentation rather than assuming local behavior transfers.

A static export has no generated response

Static export has no runtime server. Use a deployment with runtime support for request-dependent generation, or precompute a statically configured GET response when the output is fixed.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Private output is visible to another caller

Treat the route as public until authentication and authorization are added. Also review route caching: a shared cached response can expose personalized output if the cache key or policy does not distinguish users.

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 screenshot of a URL rather than a graphic built from JSX, ScreenshotNeo is a website screenshot API and MCP server. A single GET request can return PNG, JPEG, WebP, or PDF. Its clean-shot options accept cookie/consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with verdict and billing details in response headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents.

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.

Example cURL request (replace the URL and API key):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card required.

Frequently asked questions

Does ImageResponse create a PNG?

Yes. It generates PNG output from JSX rendered with its supported CSS subset.

Can I use this for a social preview image?

Yes. Dynamic Open Graph graphics are a documented use case for ImageResponse.

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

Does a Route Handler automatically make the image private?

No. Add the authentication and authorization your application requires; the route is otherwise a public endpoint.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.