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

Use PHP to control a real browser, then pass an explicit file path to its screenshot method. PHP does not render arbitrary modern webpages by itself. With Playwright for PHP, for example, the core save operation is $page->screenshot(__DIR__ . '/screenshots/page.png');. First ensure the destination directory exists and is writable by the PHP process.

What you need to save a webpage screenshot with PHP

A website screenshot captures a browser’s rendered page, including layout, styles, and loaded assets. Use a browser automation library such as Playwright for PHP or run a Puppeteer browser process or service. PHP handles the workflow and destination path; the browser engine loads and renders the page.

You will need a PHP environment, the automation library and its compatible browser runtime, a target URL, and a directory where the process can create files. Installation and browser setup depend on the library and deployment environment, so follow the relevant library’s setup documentation before using the capture examples below.

Save a screenshot to a folder with Playwright for PHP

Pass the desired filesystem path as the first argument to screenshot(). This example uses an absolute path based on the PHP file’s directory, avoiding surprises from a worker’s current working directory:

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.
<?php

// Assumes $page is an initialized Playwright PHP Page.
$directory = __DIR__ . '/screenshots';

if (!is_dir($directory) && !mkdir($directory, 0755, true) && !is_dir($directory)) {
    throw new RuntimeException("Could not create screenshot directory: {$directory}");
}

if (!is_writable($directory)) {
    throw new RuntimeException("Screenshot directory is not writable: {$directory}");
}

$page->goto('https://example.com');
$path = $directory . '/page.png';
$page->screenshot($path);

echo "Screenshot saved to {$path}";

The snippet assumes that $page has already been created using your installed Playwright PHP setup. The documented API signature is screenshot(?string $path = null, array|ScreenshotOptions $options = []): string; supplying a path writes the image there. See the Playwright PHP screenshot guide for capture options and setup context.

In a complete application, put browser startup and shutdown in your existing lifecycle and release the page or browser context after the capture. If capture fails, handle the exception in the surrounding job or request rather than reporting success merely because navigation began.

Choose the capture area and timing

Visible viewport

A normal screenshot captures what is visible in the browser viewport. Choose this when you need a view of the initial screen or a specific scrolled state. Set the viewport before navigation or capture when dimensions matter.

Full-page document

For a long page, request a full-page capture using the library’s screenshot option. Playwright PHP documents full-page screenshots. Full-page capture can produce a tall image; pages that load content only while scrolling may need additional handling to trigger that content before taking the screenshot.

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

One element

When you only need a chart, product card, or other region, capture the target element rather than the whole page. Playwright’s guide covers locator-based element screenshots. Make sure the locator identifies the intended element and that it is visible before capture.

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.

Wait for the state you need

Navigation completion does not always mean the page is visually ready: client-side rendering, fonts, images, and asynchronous content can arrive later. Wait for an appropriate selector or page state for your task. Avoid relying on an arbitrary delay as the only readiness check when a specific element or condition can be checked.

Use Puppeteer when your PHP workflow invokes a browser process

Puppeteer’s Page.screenshot() accepts a path option; its documentation describes that option as the file path to save the image to. The documented workflow navigates, captures, then shuts down the browser. If PHP invokes a Puppeteer process or service, have that process save to a path accessible to the intended consumer, or return the image data to PHP for writing.

await page.goto('https://example.com');
await page.screenshot({ path: 'screenshots/page.png' });
await browser.close();

This is JavaScript for the Puppeteer browser process, not PHP syntax. Puppeteer infers the image type from the filename extension. Relative paths resolve against the process’s current working directory, which may differ from the PHP script’s directory when launched by a worker or service. Use an absolute path or configure the working directory deliberately. See Puppeteer’s screenshot API.

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.

Make destination paths safe and predictable

  • Ensure the folder exists: create it before capture, or use a directory helper. Playwright PHP’s ScreenshotHelper documents directory creation, filename generation, cleanup by age or file count, and directory inspection.
  • Check write access: the PHP user, queue worker, or browser process needs permission to write to the destination. A directory writable by your interactive shell may not be writable by the web server.
  • Prefer an absolute path: __DIR__ anchors a path to the PHP source file. A configured storage root is preferable when files should live outside the application directory.
  • Avoid public exposure of sensitive images: store screenshots containing private or account-specific information outside publicly served directories, and authorize any later download.
  • Prevent filename collisions: concurrent jobs writing page.png can overwrite each other. Generate a unique filename per job or use a job-specific subdirectory.
  • Plan cleanup: screenshots can accumulate. Use a retention policy appropriate to the data and storage available; the Playwright PHP ScreenshotHelper includes cleanup by age or file count.

The Playwright PHP screenshot helper reference describes these directory and file-management utilities: ScreenshotHelper.

Control rendering when screenshots need to be comparable

A screenshot records a particular browser rendering, not an abstract or invariant version of a page. Results can vary with viewport size, browser version, fonts, animation state, page data, and timing. For visual comparisons, keep those conditions consistent and wait for the same meaningful page state each time.

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.

Playwright’s guidance recommends locator or DOM assertions for normal behavior checks and cautions that uncontrolled pixel comparisons can measure the machine or rendering environment rather than the product. Treat screenshots as visual evidence, and use stable rendering conditions when comparing them.

Common errors and fixes

The screenshot directory does not exist

Create the destination directory before calling the screenshot method, including parent directories if needed. Check the return value of mkdir() and confirm the directory exists afterward.

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.

Permission denied or file cannot be written

Check which operating-system user runs PHP and whether that user can write to the target directory. Correct the directory ownership or permissions, or choose a writable storage path. Avoid making a sensitive directory broadly writable as a shortcut.

The file appears in the wrong location

A relative path is resolved from the process’s current working directory, not necessarily from the PHP script’s location. Build an absolute path from __DIR__ or your configured storage root.

The image is blank or missing page content

Wait for the page state or element your capture depends on, and verify that navigation succeeded. If the site adds content after scrolling, trigger the relevant loading behavior before a full-page screenshot. A capture taken too early can faithfully save an incomplete render.

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

Concurrent captures overwrite one another

Do not give simultaneous jobs the same output filename. Include a unique job identifier or timestamp in the filename, and ensure each job writes to its intended storage location.

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

A visual comparison changes between runs

Make the browser version, viewport, fonts, content, and timing consistent. Stabilize animations or dynamic data if the use case permits. Use DOM or locator assertions for functional behavior rather than treating every pixel difference as a product defect.

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

Or skip the browser setup

ScreenshotNeo offers a website screenshot API and MCP server for developers. One GET request can return an image or PDF, so PHP can request the capture and save the response body. Here is the cURL form for a PNG capture:

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

Use the API key from your account, and see the ScreenshotNeo API documentation for request parameters and response details. In a PHP application, make the same GET request with your HTTP client and write the binary response to a file in a writable directory.

  • Cookie banners, popups, and chat widgets are removed before the shot; each cleanup step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers report the page verdict and billing status.
  • An MCP server gives AI agents tools for screenshots, page information, and PDF capture.
  • The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Choosing the right approach

Use Playwright PHP when you want browser control inside a PHP workflow and can manage the browser runtime. Use Puppeteer when your existing architecture already delegates rendering to a Puppeteer process or service. For either local approach, path correctness, write permissions, readiness, and unique filenames determine whether a capture is useful and reliably saved.

Frequently Asked Questions

Can PHP take a screenshot without a browser?

Not for an arbitrary modern webpage’s rendered appearance; use a browser engine such as Playwright or Puppeteer.

What path does Puppeteer use for a relative screenshot filename?

Puppeteer resolves a relative screenshot path against the current working directory of the Puppeteer process.

Does Playwright for PHP support element screenshots?

Yes. Its screenshot guide describes capturing a locator or element as well as viewport and full-page images.

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.