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.

To convert HTML to an image in PHP, render the markup in a real browser and save the resulting screenshot. Spatie Browsershot is a practical approach: PHP calls Puppeteer, Puppeteer controls headless Google Chrome, and Chrome produces a PNG or JPEG. You can capture a URL, an HTML string, or a local HTML file.

Choose the rendering approach first

PHP itself does not implement a modern HTML/CSS layout engine. Image libraries such as GD can draw pixels, but they do not reliably reproduce browser layout, web fonts, JavaScript, responsive CSS, or externally loaded assets. For faithful output, use one of these deployment models:

Approach What runs where Best fit Main constraint
Browsershot Your PHP application invokes Node, Puppeteer, and Chrome Private pages, generated HTML, repeatable server-side rendering You maintain compatible Node/Puppeteer/Chrome processes
Hosted renderer A vendor renders after receiving HTML or a reachable URL Teams that do not want Chrome in their deployment API key, network dependency, and assets must be reachable by the vendor

The current Browsershot 5.4.0 Packagist entry (dated 2026-05-26) lists PHP ^8.2, ext-fileinfo, ext-json, spatie/temporary-directory, and symfony/process; verify the registry before installing because requirements change.

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

Install Browsershot and its browser runtime

  1. Install the PHP package:
    composer require spatie/browsershot
  2. Install Node.js and Puppeteer in the environment that will execute the capture. Browsershot’s README describes Puppeteer as a requirement for browser operations.
  3. Ensure Chrome or Chromium can launch under the same user as PHP-FPM, your queue worker, or the CLI process. In containers, provide the browser binary and enough shared memory or configure an appropriate temporary directory.
  4. Test from the same execution context used in production. A command that works in your shell can fail under PHP-FPM because of a different PATH, user, permissions, or sandbox policy.

Browsershot’s older PhantomJS-based v1 is abandoned. The README mentions v2 for environments that cannot install Node and Puppeteer, but v2 is no longer maintained; do not choose either legacy line as a new default.

#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Convert a public webpage to PNG

This is the smallest working example:

<?php
require __DIR__ . '/vendor/autoload.php';

use SpatieBrowsershotBrowsershot;

Browsershot::url('https://example.com')
    ->save('/tmp/page.png');

The output extension selects image output here. Browsershot uses .pdf for PDF output; use .png, .jpg, or another supported image path for screenshots.

Render an HTML string or local file

HTML generated in PHP

<?php
$html = '<!doctype html>
<html><head><style>body{font-family:Arial;background:#f5f7fb;padding:40px}.card{background:white;padding:24px;border-radius:12px}</style></head>
<body><div class="card"><h1>Invoice</h1><p>Generated by PHP</p></div></body></html>';

Browsershot::html($html)->save(__DIR__ . '/invoice.png');

Existing local HTML

<?php
Browsershot::htmlFromFilePath(__DIR__ . '/templates/card.html')
    ->save(__DIR__ . '/card.png');

Use html() when a template has already been rendered to a string. Use htmlFromFilePath() when the markup is on disk. Relative CSS, images, and fonts in local documents must resolve from a location Chrome can read.

Control dimensions, format, and the captured area

Decide whether you need the visible viewport, the entire document, or one component before choosing options.

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

Viewport screenshot

Browsershot::url('https://example.com')
    ->windowSize(1440, 900)
    ->save('/tmp/desktop.png');

Full-page image

Browsershot::url('https://example.com/article')
    ->windowSize(1280, 800)
    ->fullPage()
    ->save('/tmp/article.png');

Full-page capture expands beyond the initial viewport and is useful for documents, but very tall pages can consume substantial memory. Consider splitting long content into sections if your worker has tight limits.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Capture one element

Browsershot::url('https://example.com/dashboard')
    ->select('.report-card')
    ->save('/tmp/report-card.png');

JPEG and quality

Browsershot::url('https://example.com')
    ->setScreenshotType('jpeg')
    ->setScreenshotQuality(82)
    ->save('/tmp/page.jpg');

PNG preserves sharp text and transparency. JPEG is usually smaller for photographic content but introduces lossy compression. The image documentation also supports clipping and device-scale settings; use clipping for a precise rectangle and a higher scale when you need denser pixels for retina displays.

Wait for fonts, lazy images, and JavaScript

A browser can finish the initial navigation before your application has finished rendering. Capture only after the state you need is present.

Network idle

Browsershot::url('https://example.com/catalog')
    ->waitUntilNetworkIdle()
    ->fullPage()
    ->save('/tmp/catalog.png');

Delay or selector wait

Use a short delay when a known animation or third-party widget needs time, or wait for a selector/function when you can identify a definitive ready state. Prefer a readiness selector over an arbitrary long sleep: it reduces latency and makes failures visible.

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.
Browsershot::url('https://example.com/app')
    ->waitForSelector('.dashboard-ready')
    ->save('/tmp/dashboard.png');

For lazy-loaded images, scroll or trigger the page’s loading behavior before capture, then wait for network idle. Web fonts should also be allowed to finish; otherwise Chrome may capture fallback fonts and produce a different line wrap.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Secure and deterministic input

  • Escape untrusted values before inserting them into HTML; rendering does not make HTML safe.
  • Keep output paths outside user-controlled directories and verify permissions for the PHP worker.
  • Use a fixed viewport, timezone, locale, and font set when pixel consistency matters.
  • Do not assume a private URL is reachable from a hosted renderer; local files and localhost addresses are available only to your own browser process.

Or skip the browser setup

ScreenshotNeo is a hosted screenshot API and MCP server. One request can render a URL as PNG, JPEG, WebP, or PDF. It accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and billing status.

Its 63 options include full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets or custom viewports, retina scale, PDF paper settings, custom CSS and JavaScript, pre-capture clicks, hidden selectors, selector/delay/network-idle waits, request and resource blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, configurable caching, signed image links, asynchronous signed webhooks, bulk capture of 100 URLs per call, a usage API, and an OpenAPI specification. An MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

See the ScreenshotNeo API documentation for current parameters. The following call saves a WebP response:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Equivalent PHP, Python, and Node.js calls are useful when your application already has an HTTP client:

<?php
$response = file_get_contents('https://api.screenshotneo.com/v1/shot?' . http_build_query([
    'access_key' => 'YOUR_API_KEY',
    'url' => 'https://stripe.com',
]));
file_put_contents(__DIR__ . '/shot.webp', $response);
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
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}`);

The Free plan includes 1,000 shots per month without a card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan, and annual billing provides two months free. Create a free ScreenshotNeo account to try it.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Hosted PHP rendering: when it fits

HTML to Image’s PHP SDK is another hosted model. Its documentation requires PHP 8.3 or newer, Guzzle, cURL, and an API key. The vendor renders on its infrastructure, so your application does not install Chrome or tune local shared memory. However, the renderer must reach every referenced stylesheet, image, font, and script; localhost resources are not reachable from its servers. Treat its documented 50 starting credits as a mutable offer and confirm the current terms before budgeting.

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

Troubleshoot common failures

“Chrome executable not found” or process exit errors

Install a compatible Chrome/Chromium binary, install Puppeteer, and configure the executable path if your environment does not expose it on PATH. Test as the web-server or queue user, not only as your login.

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

The image is blank or missing styles

Check that CSS, fonts, and images return successful responses from the rendering environment. For local HTML, use readable absolute paths or a correctly based document. For remote pages, inspect authentication, redirects, and blocked mixed-content requests.

Content appears before the screenshot

Wait for a stable selector, network idle, or a documented application-ready condition. Increase a delay only after identifying what is still loading.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Fonts or layout differ between machines

Install the same fonts, set a fixed viewport and device scale, and avoid relying on nondeterministic timestamps or animations. Disable animation in custom CSS when visual diffs must be stable.

PHP times out

Move captures to a queue, set an HTTP and process timeout appropriate to page complexity, and avoid capturing unbounded full-page documents in a synchronous request. For high-volume jobs, caching or a hosted service can reduce browser startup overhead.

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

Performance, reliability, and cost decisions

  • Browsershot: no per-image vendor charge is described in the package documentation, but you pay operationally for Chrome memory, CPU, patching, and queue capacity. It is the strongest choice when source HTML is private or local.
  • Hosted API: avoids browser maintenance and can simplify scaling, but requires outbound network access, credentials, provider availability, and publicly reachable assets. Do not send confidential markup unless the provider’s terms and your data policy permit it.
  • Repeat captures: use deterministic inputs and caching where appropriate. ScreenshotNeo lets you choose a cache TTL and reports cache hits as non-billed responses.

FAQ

Can PHP convert HTML to PNG without Chrome?

Not with browser-level CSS and JavaScript fidelity. Use a maintained browser runtime such as Browsershot/Puppeteer, or delegate rendering to a hosted API.

Should I use PNG or JPEG?

Choose PNG for text, UI, transparency, and lossless output; choose JPEG with an explicit quality for smaller photographic images.

Can a renderer capture localhost?

Your own Browsershot process can access local resources it is permitted to read. A hosted renderer generally cannot access your localhost; its documentation specifically warns that localhost assets are unreachable from its servers.

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.

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