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

PHP can save screenshots, but the right method depends on what you need to capture. GD can grab an existing desktop or window; Imagick can process an image but cannot render a webpage; Chrome and Selenium can render pages in a browser. For a JavaScript-heavy webpage, start with headless Chrome or a PHP Chrome library. If you want to avoid managing a browser, a hosted API is another option.

Choose the method that matches the capture

Method What it captures or does Main dependency Best fit
GD screen or window capture An existing desktop screen or window GD support and an available desktop context Capturing a visible application, not rendering a webpage on a server
Imagick Processes an image made by another method The Imagick PHP extension and ImageMagick Resizing, converting, annotating, composing, or optimizing captures
Headless Chrome A webpage rendered in Chromium at a chosen viewport Chrome or Chromium installed on the machine Capturing pages that rely on HTML, CSS, or JavaScript
chrome-php/chrome A webpage captured through a PHP library controlling Chrome or Chromium Composer, the library, and a Chrome or Chromium executable Using a PHP API for viewport, clipped, or full-page captures
Selenium WebDriver The current browser context or an individual element A PHP Selenium client, compatible browser driver, and browser Adding screenshots to browser automation or tests

1. Capture an existing screen or window with GD

GD provides imagegrabscreen() for the screen and imagegrabwindow() for a window. These functions capture an existing desktop context; they do not open a URL and render its HTML. They are useful when PHP runs where the application is already visible, but they are generally the wrong tool for producing webpage screenshots from a headless web server.

First confirm that GD is enabled in the PHP build running your script. A minimal screen-capture pattern is:

<?php
$image = imagegrabscreen();
if ($image === false) {
    throw new RuntimeException('Could not capture the screen.');
}

$path = __DIR__ . '/screen.png';
if (!imagepng($image, $path)) {
    imagedestroy($image);
    throw new RuntimeException('Could not write the PNG file.');
}
imagedestroy($image);

Use imagegrabwindow() instead when you need a particular window and have its window identifier. GD output functions such as imagepng() and imagejpeg() can write to a file or send image data to a browser. Check the return value and ensure the PHP process has permission to write the destination.

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.

2. Use Imagick to process a screenshot

Imagick is not a webpage screenshot renderer. It is a PHP extension for the ImageMagick API, so use it after another tool has produced an image. It can resize, annotate, compose, convert, or optimize image files.

For example, this resizes an existing capture and writes a JPEG:

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.
<?php
$image = new Imagick(__DIR__ . '/capture.png');
$image->resizeImage(1200, 0, Imagick::FILTER_LANCZOS, 1);
$image->setImageFormat('jpeg');
$image->writeImage(__DIR__ . '/capture.jpg');
$image->clear();
$image->destroy();

Install and enable the Imagick extension in the same PHP environment that runs the script. The source image still has to come from GD, a browser tool, or another capture method.

3. Render a webpage with headless Chrome

Headless Chrome is the direct command-line choice when the screenshot must reflect a webpage rendered with browser HTML, CSS, and JavaScript. Chrome’s headless shell accepts --screenshot; add --window-size=WIDTH,HEIGHT to set the viewport. For example:

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.
chrome --headless --screenshot=screenshot.png --window-size=1440,900 https://example.com

Replace chrome with the Chrome or Chromium executable available on your system. The window-size option controls the viewport; it does not by itself request a full-page capture. From PHP, invoke the browser as a separate process, use a fixed or validated URL, escape every argument, and check both the process exit status and whether the expected output file exists before treating the capture as successful.

Avoid concatenating an untrusted URL into a shell command. Besides command-injection risk, the browser process needs permission to run and write the screenshot. Local browser installation, version compatibility, and runtime isolation are operational responsibilities of this approach.

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

4. Control Chrome through chrome-php/chrome

The chrome-php/chrome library provides a PHP interface for starting Chrome or Chromium in headless mode, navigating to a URL, waiting for navigation, and saving a screenshot. The project describes it this way: “This library lets you start playing with chrome/chromium in headless mode from PHP.” It requires Composer installation and a Chrome or Chromium executable accessible to the PHP process.

Its documented screenshot options include PNG, JPEG, and WebP output, clipping a region, and full-page capture using captureBeyondViewport with a full-page clip. Choose this route when you want browser control from PHP without assembling command-line arguments yourself. Confirm that your installed library version and browser support the options you rely on, and handle navigation failures and output-file checks in your application.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

5. Capture through Selenium WebDriver

Selenium is a good fit when the screenshot is part of an existing browser test or automation flow. A PHP implementation needs a Selenium client, a compatible browser driver, and the browser itself. WebDriver can capture the current browsing context; its API can also capture individual elements. The returned screenshot data can be saved as a PNG or handled as bytes or base64.

  1. Start or connect to a WebDriver session using the browser and driver configured for your test environment.
  2. Navigate to the page and wait for the test’s required state, rather than assuming the page is ready as soon as navigation begins.
  3. Capture the current context or locate the target element and use the element screenshot API.
  4. Save or decode the returned screenshot data, then check that the file was written before using it.

Selenium adds browser and driver setup, but it can avoid building a separate capture workflow when your application already uses WebDriver for tests.

Or skip the browser setup

ScreenshotNeo is a hosted website screenshot API and MCP server. Its API returns a screenshot or PDF from one GET request; the service manages the browser. The API can accept a URL and return PNG, JPEG, WebP, or PDF output.

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 API documentation for request parameters and options. Before a capture, it accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses include X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.

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

The Free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots. Sign up for ScreenshotNeo’s free plan to try it without a card.

Which method should you use?

  • Choose GD when you need to capture a screen or window that already exists in a desktop environment.
  • Choose Imagick only when you already have an image to transform; it does not render a webpage.
  • Choose headless Chrome for a straightforward browser-rendered screenshot from a command line or controlled PHP process.
  • Choose chrome-php/chrome when you want a PHP library to control Chrome and need viewport, clipped, or full-page capture.
  • Choose Selenium when capture belongs in an existing WebDriver test or automation suite.
  • Choose a hosted API when you prefer not to operate a local browser; account for the service dependency and review its privacy handling and current limits.

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.