Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
For a faithful screenshot of a modern web page, have PHP control a real browser engine. The browser runs the page’s HTML, CSS and JavaScript; PHP then saves a viewport, full-page or element screenshot. Playwright PHP is a direct option, while Spatie Browsershot offers a shorter PHP wrapper over Puppeteer.
Choose the right PHP screenshot approach
The best choice depends less on syntax than on what you can run in your environment. A JavaScript-rendered page needs a browser; PHP alone cannot reproduce its rendered appearance by simply fetching the HTML.
| Approach | Best fit | What to plan for |
|---|---|---|
| Playwright PHP | PHP applications that need direct page, full-page and element screenshot controls. | The documented examples require PHP 8.2 or newer and Node.js 20 or newer, plus an installed browser. |
| Spatie Browsershot | Laravel and PHP projects that want a concise URL-to-image or HTML-to-image API. | It uses Puppeteer behind the scenes, so deployment needs the Node/Puppeteer/Chromium runtime expected by the version you choose. |
| Direct Puppeteer via Node | Teams that already operate Node browser workers or services. | It offers low-level control but adds process, deployment and PHP-to-Node communication complexity. |
For a PHP-only application environment without a browser runtime, a hosted screenshot API can avoid installing and operating Chromium locally; that trade-off is covered after the self-hosted examples.
Recommended Free Tools
Take a screenshot with Playwright PHP
Install the package and browser
In a project with Composer, install the Playwright PHP package using the command specified by its current package documentation. Install the compatible browser as directed there, and confirm the PHP and Node.js versions meet the documented requirements before running the capture. The official guide’s examples list PHP 8.2 or newer and Node.js 20 or newer.
#1 Best Overall
Keep browser installation and package versions consistent between development and CI. The browser is doing the rendering, so a screenshot may change if the browser version, fonts or operating-system rendering environment changes.
Capture the visible viewport
This minimal example opens Chromium, navigates to a page and writes a PNG screenshot:
<?php
use PlaywrightPlaywright;
$playwright = Playwright::create();
$browser = $playwright->chromium()->launch();
$page = $browser->newPage();
$page->goto('https://example.com');
$page->screenshot(__DIR__ . '/artifacts/example.png');
$browser->close();
Create the artifacts directory before running the snippet, or change the output path to an existing writable directory. For production or repeated captures, put browser cleanup in a finally block so an exception during navigation does not leave the browser running:
<?php
use PlaywrightPlaywright;
$playwright = Playwright::create();
$browser = $playwright->chromium()->launch();
try {
$page = $browser->newPage();
$page->goto('https://example.com');
$page->screenshot(__DIR__ . '/artifacts/example.png');
} finally {
$browser->close();
}
A viewport capture records the visible page area. It is appropriate when the screenshot should represent what a user sees without scrolling.
Capture the whole page or one element
Use a full-page screenshot when below-the-fold content matters; use a locator screenshot when the subject is a particular component rather than the entire page. The Playwright PHP screenshot guide documents page, full-page and locator/element screenshots. The exact method options can vary with the installed package version, so use that version’s API reference for option names:
- Viewport: screenshot the current viewport for a screen-state capture.
- Full page: enable the full-page option to include content beyond the viewport. Very long pages may create extremely tall image files and use more memory.
- Element: locate the target component and screenshot that locator to exclude unrelated content.
These are different outputs, not interchangeable settings: full-page capture is useful for documents and long landing pages, while an element capture is usually better for a card, chart, invoice or test assertion.
Rank #2
Wait for the page state you need
Navigation completing does not always mean that a page is visually ready. A page may still be loading images, fetching data, applying fonts or animating a component. Choose a wait condition that represents the desired state—for example, waiting for a specific selector when the target is a known component—rather than relying on an arbitrary short delay. If the page uses delayed content, verify that the screenshot contains it before treating the capture as complete.
For an authenticated page, create the browser context with the required cookies or storage state before navigation. Never put real credentials or session secrets into source control, screenshot artifacts or CI logs.
Use Spatie Browsershot for a shorter PHP wrapper
Browsershot’s concise API is useful in Laravel or general PHP projects when you want to save a URL or HTML string as an image or PDF:
<?php
use SpatieBrowsershotBrowsershot;
Browsershot::url('https://example.com')
->save(__DIR__ . '/example.png');
Browsershot::html('<h1>Hello world!!</h1>')
->save(__DIR__ . '/example.png');
Those calls demonstrate URL-to-image and HTML-to-image flows. The project documentation says Browsershot can convert a web page to an image or PDF. Since it is a wrapper around Puppeteer, it does not remove the browser-runtime requirement: install and configure the Node, Puppeteer and Chromium versions expected by the Browsershot version in your project. A wrapper shortens application code; it does not make rendering happen without a browser.
Call Puppeteer directly when Node is already part of the system
Puppeteer’s Page.screenshot() API can return image bytes as a Uint8Array or a base64 string. A PHP application can send a request to a small Node worker or service, which launches the browser, captures the page and returns the bytes or a stored artifact path.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →This is a sensible boundary when a team already maintains Node browser workers. If it does not, the service adds deployment work: process supervision, request and response handling, failure propagation, browser lifecycle management and a clear policy for where image files live. For a PHP-centric project, Playwright PHP or Browsershot usually keeps the application-facing code more direct.
Make screenshots reliable and useful
Control rendering inputs
A screenshot is an artifact of both the page and its rendering environment. For repeatable output—especially image-diff tests—control the following:
- Viewport: use the same width and height each run so responsive breakpoints do not shift the layout.
- Fonts: ensure the required fonts are installed and loaded before capture; fallback fonts change line breaks and element dimensions.
- Animations: wait for or disable motion that makes the captured frame vary from run to run.
- Data and page state: use stable test data and wait for the exact content that should appear.
- Browser version: keep the browser consistent between local runs and CI when comparing pixels.
The Playwright PHP guide cautions that uncontrolled rendering environments can make image diffs test the machine rather than the product. Treat a visual difference as a potentially environmental change until these inputs are controlled.
Choose an output format for the job
- PNG is a safe default for lossless text and interface captures.
- JPEG or WebP can reduce file size where the capture API and workflow support quality settings.
- PDF is appropriate for document-style output or a printable page rather than a pixel image.
Format support and quality controls depend on the library and the API you use; check the relevant version’s options before assuming an image format or compression setting is available.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Save and handle artifacts deliberately
Write screenshots to a predictable CI-upload directory or a deliberate application storage location. Set retention and cleanup rules for old files, and avoid capturing secrets, personal information or authenticated content that should not be retained. If a capture is evidence for a test, preserve enough context to identify the page state and browser version without logging credentials.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server for developers. Send one GET request with a URL to receive a PNG, JPEG, WebP or PDF. The service accepts cookie and consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each cleanup step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and responses identify the page verdict and billing status in headers.
Here is the cURL call, with the target URL set to https://example.com:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
See the ScreenshotNeo documentation for setup and request options. If you need browser-local control, authentication state or custom runtime behavior, a locally operated browser may be the better fit. If you want an API call instead, the practical differences are that cookie banners, popups and chat widgets are removed before the shot; bot checks, blank pages and failed loads are never billed; an MCP server lets AI agents take screenshots; and 1,000 screenshots a month are free with no card, with paid plans starting at $5 for 3,000.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesSign up for the free plan: 1,000 screenshots a month, no card required.
Rank #4
Troubleshoot common capture failures
The page is blank or missing JavaScript content
Likely cause: the capture occurred before the page’s scripts or data finished rendering, or the environment is missing a required browser runtime. Fix: confirm the browser launches correctly, wait for the specific content or selector, and inspect the page state before saving the screenshot.
Fonts, line breaks or layout differ in CI
Likely cause: a different browser version, missing fonts, a changed viewport or unstable page data. Fix: pin the browser environment, install the expected fonts, standardize the viewport and use predictable data.
The full-page image is too large or slow to handle
Likely cause: the page contains a great deal of below-the-fold content. Fix: capture the viewport if only the visible state matters, or target a locator if only one component is needed. For a document workflow, consider whether PDF output better matches the intended result.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallThe screenshot file is not created
Likely cause: the destination directory does not exist, is not writable, or the browser failed before the save call. Fix: create the directory, check permissions, and surface navigation and browser exceptions in application logs without exposing secrets.
Browsershot cannot find or launch Chromium
Likely cause: the deployed environment lacks the Node/Puppeteer/Chromium runtime or has versions/configuration that do not match the installed package. Fix: install the runtime required by your chosen Browsershot version and verify the same setup in CI and production.
Captures of private pages show a login screen
Likely cause: the browser context does not have the session cookies or storage state used by the application. Fix: provide the required authentication state securely before navigation and ensure it is scoped to the capture task.
Cost and operating trade-offs
Self-hosted Playwright, Browsershot and Puppeteer require you to operate the browser runtime and handle its resource use, storage and failures. That gives you control over browser context and page interaction, but screenshots can be expensive in memory and time when pages are long or many captures run concurrently. Set concurrency limits appropriate to your server and clean temporary artifacts.
A hosted API shifts browser operations out of the PHP deployment, but introduces an external service, API credentials and per-plan usage limits. ScreenshotNeo’s published plans are:
| Plan | Monthly screenshots | Price |
|---|---|---|
| Free | 1,000 | $0; no card |
| Starter | 3,000 | $5 |
| Growth | 15,000 | $15 |
| Pro | 60,000 | $39 |
| Scale | 250,000 | $99 |
| Business | 1,000,000 | $249 |
Yearly billing gives two months free, and every listed feature is available on every plan. Select between local and hosted capture based on control, deployment complexity and expected volume rather than image format alone.
Frequently asked questions
Can PHP take a screenshot without a browser?
Not faithfully for a modern page whose appearance depends on CSS and JavaScript. Use PHP to control a browser engine, or call a hosted screenshot service.
Can I screenshot HTML that is not hosted on a website?
Yes. Browsershot’s html() flow accepts an HTML string and saves it as an image; for other libraries, consult the installed version’s support for loading local or inline content.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Which PHP option should I start with?
Start with Playwright PHP when you want direct browser and screenshot controls, or Browsershot when a concise wrapper fits your PHP application and you can provide its Node/Puppeteer/Chromium runtime.
Quick Recap
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.

