October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk7 min

Abstract Screenshot API Example: Capture a Website Screenshot in PHP

A PHP cURL example for Abstract’s Website Screenshot API, with safe image handling, capture options, limits, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To capture a website in PHP with Abstract’s Screenshot API, send an HTTPS GET request to https://screenshot.abstractapi.com/v1/ with your API key and the target URL, then save the successful response body as image bytes. Abstract presents this as a hosted REST API, not a PHP screenshot library; the example below is an article-provided cURL implementation of the documented request, not an official PHP sample. Check Abstract’s live API reference for current parameter details before adding capture options.

Make a screenshot request from PHP

Get an Abstract API key and keep it on the server. The product page’s basic request uses the api_key and url query parameters. This example uses PHP’s cURL extension, encodes both values, sets a timeout, verifies the HTTP response and content type, and writes the response only after those checks succeed.

Runnable PHP example

Set the environment variable ABSTRACT_API_KEY to your key, then save this as screenshot.php and run it with PHP CLI:

<?php
$apiKey = getenv('ABSTRACT_API_KEY');
if ($apiKey === false || $apiKey === '') {
    throw new RuntimeException('Set the ABSTRACT_API_KEY environment variable.');
}

$targetUrl = 'https://example.com';
$endpoint = 'https://screenshot.abstractapi.com/v1/';
$query = http_build_query([
    'api_key' => $apiKey,
    'url' => $targetUrl,
], '', '&', PHP_QUERY_RFC3986);

$ch = curl_init($endpoint . '?' . $query);
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_TIMEOUT => 90,
]);

$body = curl_exec($ch);
if ($body === false) {
    $error = curl_error($ch);
    curl_close($ch);
    throw new RuntimeException('Screenshot request failed: ' . $error);
}

$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE) ?: '';
curl_close($ch);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException('Screenshot API returned HTTP ' . $status . ': ' . substr($body, 0, 1000));
}
if (stripos($contentType, 'image/') !== 0) {
    throw new RuntimeException('Expected an image response; received ' . ($contentType ?: 'an unspecified content type') . ': ' . substr($body, 0, 1000));
}

$file = __DIR__ . '/screenshot';
$extension = stripos($contentType, 'png') !== false ? '.png'
    : (stripos($contentType, 'gif') !== false ? '.gif' : '.jpg');
if (file_put_contents($file . $extension, $body) === false) {
    throw new RuntimeException('Could not write the screenshot file.');
}
echo 'Saved ' . $file . $extension . PHP_EOL;

Replace https://example.com with the page you are authorized to capture. The code uses the endpoint and query parameter names shown on Abstract’s product page. Its official documentation index confirms a Website Screenshot API reference, but the official material does not provide a PHP-specific sample or fully expose parameter syntax; verify any additional options against the live reference: Abstract Website Screenshot API and Abstract API documentation index.

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

Serve the image from a PHP page

To return the saved file to a browser, send the corresponding image content type and stream the bytes rather than printing debug output first:

<?php
$path = __DIR__ . '/screenshot.jpg'; // Use the actual extension saved above.
if (!is_file($path)) {
    http_response_code(404);
    exit('Screenshot not found');
}
header('Content-Type: image/jpeg');
header('Content-Length: ' . filesize($path));
readfile($path);

For a dynamic implementation, derive the content type from the validated API response and use a fixed or safely generated local filename. Do not accept an arbitrary output path from a request parameter.

What the API can capture

Abstract describes its service as accepting either a URL or raw HTML and returning an image, with JPEG, PNG, and GIF among the formats it advertises. It also describes controls for format, viewport or dimensions, image resizing and cropping, custom CSS, and capture delay. These are vendor-described capabilities; check the current parameter names and permitted values in the API reference before relying on a particular option.

The service describes rendering HTML, CSS, SVG, webfonts, graphs, and images. Abstract’s stated use cases include device QA, recurring snapshots, embedded previews, website monitoring, and safer previews in security flows. These are examples from the vendor, not independent performance validation.

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

Abstract’s product FAQ says screenshots from different locations are not currently supported and are planned for a future version. Because availability can change, confirm this limitation with the live product documentation if geography matters to your use case.

Secure credentials and handle responses safely

  • Keep the key private. Do not put it in browser JavaScript, public HTML, or a source-control repository. Read it from server-side configuration or an environment variable.
  • Be mindful of query-string logging. Abstract’s shown request puts api_key in the URL query. Web-server, proxy, or application logs can therefore expose it if full URLs are recorded. Limit or redact those logs and rotate a key if it is disclosed.
  • Validate before saving. A non-success response may contain an error body rather than image bytes. Check status and content type before writing the response as a file.
  • Set timeouts and bound work. Screenshot rendering depends on loading a page; the example’s 90-second total timeout prevents an indefinitely blocked PHP process. Choose a limit appropriate to your application and handle timeout failures.
  • Control user-supplied URLs. If your feature lets users choose a target, validate allowed schemes and destinations and consider server-side request-forgery risks. Do not turn an unrestricted URL parameter into a proxy to internal services.
  • Protect output locations. Use a controlled storage directory, generated filenames, and appropriate file permissions. Avoid exposing sensitive captures through a public directory by default.

Troubleshooting common failures

Symptom Likely cause What to check
PHP reports that cURL functions are undefined The PHP cURL extension is not installed or enabled. Enable/install the extension for the same PHP runtime that executes the script, then restart the relevant service if required.
The script says the API key is missing ABSTRACT_API_KEY is not set in the environment seen by PHP. Set it for the CLI or web-server process that runs the script; a shell variable in another session may not be inherited.
HTTP error response The key, request parameters, account allowance, target URL, or service response may be at fault. Inspect the status and a limited, sanitized portion of the response body. Confirm credentials and exact parameter requirements in Abstract’s live API reference; do not log the full URL containing the key.
Response is not an image The API may have returned an error payload or a different response than expected. Check status before content type, inspect the response safely, and avoid saving it with an image extension.
Connection timeout The request or target page took longer than the configured limit, or network access failed. Check outbound HTTPS access from the PHP host and adjust timeouts only if the application can safely wait longer.
File write fails The destination directory is missing or PHP lacks write permission. Use a controlled writable directory and check the result of file_put_contents.

Limits, pricing, and operational considerations

Abstract’s product page currently displays a Free plan at $0 with 100 requests and a limit of 1 request per second. Its Standard plan display is inconsistent: the monthly billing view shows $99 per month, paid annually, with 60,000 requests per month and a 3-request-per-second limit, while the yearly billing view shows 60,000 requests per year. Do not treat either Standard quota as universal; verify the current pricing and account view before estimating capacity. Enterprise pricing is listed as custom, and the vendor page describes a 99.99% uptime SLA and enterprise support features. These are vendor-published figures and claims, not independently audited service results.

A hosted API avoids building and maintaining your own browser-rendering infrastructure, but it makes capture behavior, request limits, pricing, and availability dependent on the vendor. This article does not establish comparative latency, image quality, or total cost versus self-managed browsers. Abstract also presents a privacy statement that it earns revenue from API subscriptions rather than selling user data; consult its linked privacy policy and terms for the details that apply to your use case.

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 is a website screenshot API and MCP server. One GET request returns an image or PDF; cookie banners are accepted like a visitor and more than 60 known consent platforms, newsletter popups, and chat widgets are removed before capture, with each step configurable. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status. Its MCP server offers screenshot tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000. See ScreenshotNeo and the API documentation.

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://example.com -o shot.webp

Use access_key server-side and replace the example URL with your target. Sign up for 1,000 free screenshots a month with no card.

Frequently Asked Questions

Does Abstract provide an official PHP SDK or PHP example?

The official material available for this article did not establish a PHP-specific sample or SDK. The PHP cURL code here implements the documented HTTP GET request.

Can the Abstract Screenshot API take screenshots from a chosen country?

Abstract’s product FAQ says location-specific screenshots are not currently supported; check the live documentation because availability may change.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.