October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
curl

How to Take a Website Screenshot with PHP Without Loading the DOM

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

You can take a website screenshot from PHP without running Selenium or Chrome in your PHP application: send the target URL and capture options to a hosted screenshot API, then save the returned image. PHP is not a web-page renderer, though. A browser engine still has to load, lay out, and paint the page somewhere; a hosted service simply does that work outside your PHP process.

What “without loading the DOM” means

A screenshot of a website is an image of a rendered page, not a picture that PHP can derive from an ordinary HTTP response. A browser engine must interpret the page, calculate layout, and paint pixels. With a hosted screenshot API, that browser runs remotely; your PHP code submits a URL and receives the image or a link to it. Your PHP process does not need to launch Chrome or inspect the page’s DOM.

That distinction matters if you mean “without a browser anywhere”: that is not how faithful website screenshots work. If you mean “without installing or controlling a browser on my PHP server,” a hosted renderer is the practical route, especially on shared hosting.

Why PHP’s screen-capture function does not screenshot a URL

PHP’s imagegrabscreen() captures the current Windows desktop. The PHP manual describes it as capturing the whole screen; it is documented as Windows-only and returns a GD image object on success. It does not open a URL or render a web page. See the PHP manual.

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

It is therefore unsuitable for a typical web application that needs to capture an arbitrary website address. The alternatives are to ask a rendering service to capture the page or to operate a browser yourself in a separate worker or service.

Use a hosted screenshot API from PHP

A hosted API is usually the simplest option when PHP runs on shared hosting or when you do not want to deploy and maintain a browser. The general integration is: prepare a URL and approved options, make an HTTP request with an API key, check the result, and store the returned image or response URL. Authentication, parameter names, endpoint, and response format vary between providers, so use the chosen service’s current API contract.

PHP cURL example for a generic provider

This example illustrates the common JSON-request/raw-image-response pattern. The endpoint is deliberately a placeholder: replace it and its authentication details with those documented by your selected provider. Some services instead return JSON containing a URL to the generated image.

<?php
declare(strict_types=1);

$apiKey = getenv('SCREENSHOT_API_KEY');
if ($apiKey === false || $apiKey === '') {
    throw new RuntimeException('SCREENSHOT_API_KEY is not configured');
}

$payload = [
    'url'       => 'https://example.com',
    'width'     => 1200,
    'height'    => 630,
    'full_page' => false,
    'format'    => 'png',
];

$ch = curl_init('https://provider.example/v1/screenshot');
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 60,
    CURLOPT_HTTPHEADER     => [
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS     => json_encode($payload, JSON_THROW_ON_ERROR),
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$error = curl_error($ch);
curl_close($ch);

if ($body === false) {
    throw new RuntimeException('Screenshot request failed: ' . $error);
}
if ($status < 200 || $status >= 300) {
    throw new RuntimeException('Screenshot provider returned HTTP ' . $status);
}

$output = __DIR__ . '/screenshot.png';
if (file_put_contents($output, $body) === false) {
    throw new RuntimeException('Could not write screenshot to ' . $output);
}

Install and enable PHP’s cURL extension if it is not available in your hosting environment. Keep the API key outside source control, for example in an environment variable or your hosting provider’s secret configuration. Do not expose it in browser-side JavaScript.

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

Check the response before saving it

The example assumes successful responses contain raw image bytes. If the provider returns JSON, decode the response and use the documented image URL or job identifier instead; do not save a JSON error or response body with a .png extension and treat it as an image. For asynchronous jobs, follow the provider’s documented polling or webhook flow before retrieving the finished capture.

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

Choose capture options for the page you need

Parameter names differ across APIs. Confirm the exact spelling and supported values in the provider documentation rather than assuming these generic concepts map directly to a particular endpoint.

Control What it changes When to use it
Viewport width and height The simulated browser frame, which affects responsive breakpoints and layout. Use known dimensions when you need a repeatable preview, such as a social card or a desktop/mobile comparison.
Full-page capture Captures beyond the initial viewport through the page’s scrollable height. Use for long articles or landing pages. Lazy-loaded content may require a wait or scrolling behavior supported by the provider.
Element selector Targets a specific page element rather than the whole viewport. Useful for a hero, product card, or pricing panel; the selector must match an element present when capture occurs.
Injected CSS or hide rules Changes or hides visual elements before the image is taken. Use for overlays or layout adjustments when permitted by the provider and the target site.
Readiness or delay Gives the page time to load content or wait for a specified condition. Use when client-rendered content, images, or asynchronous UI are missing from an early capture.
Output format Determines the returned image encoding. PNG is lossless; JPEG is often smaller for photographic content. WebP or AVIF can reduce transfer size if supported by the provider and your downstream use.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. Its PHP integration can call the API directly; the service renders the page remotely, so you do not run Chrome in your PHP process. The endpoint returns an image, and the API supports PNG, JPEG, WebP, or PDF output. See the ScreenshotNeo API documentation for request options and response details.

Here is a PHP cURL request using the documented GET endpoint and a URL-encoded target:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<?php
declare(strict_types=1);

$accessKey = getenv('SCREENSHOTNEO_API_KEY');
if ($accessKey === false || $accessKey === '') {
    throw new RuntimeException('SCREENSHOTNEO_API_KEY is not configured');
}

$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.screenshotneo.com/v1/shot?' . http_build_query([
        'access_key' => $accessKey,
        'url'        => 'https://stripe.com',
    ]),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 90,
]);

$image = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$error = curl_error($ch);
curl_close($ch);

if ($image === false) {
    throw new RuntimeException('Screenshot request failed: ' . $error);
}
if ($status < 200 || $status >= 300) {
    throw new RuntimeException('ScreenshotNeo returned HTTP ' . $status);
}

if (file_put_contents(__DIR__ . '/shot.webp', $image) === false) {
    throw new RuntimeException('Could not save screenshot');
}

The example uses the required access key and URL parameters. Choose any additional capture settings from the API documentation and save the output using an extension that matches the format you request.

  • Cookie or consent banners are accepted like a visitor would accept them, and more than 60 known consent platforms, newsletter popups, and chat widgets are removed before capture; each step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; responses identify the page verdict and billing status in X-Page-Verdict and X-Billed headers.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
  • The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is on every plan.

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

When self-hosting a browser makes sense

If the page is private, must be reached only from your network, or needs browser behavior and credentials that a hosted service cannot safely or appropriately handle, run browser automation in infrastructure you control. In a PHP application, a common design is for PHP to enqueue a capture request for a separate worker or browser service, then retrieve the resulting file or job status.

This gives you more control over browser configuration and access to internal pages, but transfers operational responsibility to you: browser deployment and patching, memory allocation, execution limits, worker isolation, and failure recovery. It is not simply a PHP function call, and the browser still renders the DOM even if PHP never receives it.

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.

Protect your application when accepting URLs

A screenshot endpoint that accepts arbitrary user-supplied URLs can become a server-side request risk. A renderer may be able to reach destinations the user should not control, depending on its network access and your integration. Validate and constrain destinations before forwarding them.

  • Prefer a fixed allowlist of permitted hostnames when the product can support it.
  • Reject unexpected schemes and malformed URLs; do not assume that a string beginning with a familiar hostname is safe.
  • Consider redirects: a permitted public URL could redirect to a different destination. Apply restrictions at the rendering service or enforce them in a controlled fetch layer where possible.
  • Do not forward internal credentials or unrestricted cookies to user-selected sites.
  • Apply request quotas and authentication to your own screenshot feature so it cannot be used as an open proxy or abused to generate unexpected costs.

Provider-side policies and network protections differ. Review the selected service’s current URL and destination restrictions, and do not assume that validating syntax alone prevents access to sensitive hosts.

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

Troubleshooting PHP website screenshots

cURL is unavailable or the request fails immediately

Check that the PHP cURL extension is installed and enabled for the same PHP runtime serving the application. If curl_exec() returns false, record the cURL error in server logs without exposing API credentials to users.

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

The saved file is not a valid image

Verify the provider’s response contract and HTTP status before writing the body. A JSON error, rate-limit response, or job receipt is not image data. Inspect the content type or decode the documented JSON response, then retrieve the actual image if the API returns a URL.

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

The screenshot is blank or missing content

The target may need more time, may render content asynchronously, or may require a readiness condition. Increase or refine the wait option supported by the service; for lazy-loaded images, use a full-page or scroll-aware capture mode when available. A blank result can also indicate that the target blocked or failed to load in the rendering environment.

The cookie banner, chat widget, or popup covers the page

Use the provider’s consent handling or removal feature if available. Otherwise, use a documented CSS hide rule or injected script where allowed. A generic CSS selector may not work if the overlay is inside an iframe or shadow root, so confirm the page structure and capture service capabilities.

The capture times out

Check whether the target responds reliably, whether a wait condition is too strict, and whether your PHP timeout permits the request to finish. A remote render can take longer than a normal API call because it must load and render the page. For longer jobs, use the provider’s asynchronous job or webhook mechanism if offered instead of keeping a PHP request open indefinitely.

The page looks different from the browser on your computer

Compare viewport dimensions, device settings, cookies, authentication, locale, and readiness timing. Responsive sites change layout based on viewport; dynamic pages may also vary by session or geographic context. A screenshot API renders in its own environment, not in the visitor’s local browser.

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

Performance, reliability, and cost decisions

Each capture requires remote page rendering, so avoid launching duplicate requests when the same URL and settings can reuse a result. Use caching where freshness requirements allow, and set an explicit timeout so a slow target cannot hold a PHP worker indefinitely. If a provider offers asynchronous captures, they can suit workflows that do not need the image in the same web request.

Hosted APIs trade infrastructure work for provider dependence, quotas, and service cost. Confirm current plan limits, pricing, output behavior, and URL policies directly with the provider before building them into a production budget; those terms can change. Self-hosted browsers avoid a per-call rendering service but require capacity planning and ongoing security maintenance.

For a PHP site on shared hosting, a hosted API is generally the least operationally demanding way to capture public pages. For private content or specialized browser control, a separately managed browser worker may be a better fit. In either case, PHP is coordinating the capture; a browser engine is doing the rendering.

Frequently Asked Questions

Does PHP have a built-in function to screenshot a website URL?

No. PHP’s imagegrabscreen() captures the current Windows desktop, not a URL rendered as a webpage.

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

Can I take a full-page screenshot from PHP?

Yes, if the screenshot service or browser worker supports full-page capture. Send its full-page setting with the URL and account for lazy-loaded content.

Can I use this approach on shared hosting?

A hosted screenshot API called over cURL is often suitable when the host does not let you install or run a browser. Check that cURL is enabled and that outbound HTTPS requests are allowed.

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 *

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.

Read next

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver 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.