PHP
Screenshot API for PHP
Works on shared hosting, where installing a headless browser was never an option.
screenshot api php · request and resultPAGECAPTURE / 01
PHP
<?php
function capture(string $url, string $path = 'shot.png'): void
{
$handle = curl_init('https://api.pagecapture.dev/v1/take');
curl_setopt_array($handle, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-Access-Key: ' . getenv('PAGECAPTURE_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'url' => $url,
'format' => 'png',
'full_page' => true,
]),
CURLOPT_TIMEOUT => 120,
]);
$body = curl_exec($handle);
$status = curl_getinfo($handle, CURLINFO_RESPONSE_CODE);
curl_close($handle);
if ($status !== 200) {
$error = json_decode($body, true);
throw new RuntimeException("{$error['error_code']}: {$error['error_message']}");
}
file_put_contents($path, $body);
}Capture result
succeededhttps://example.com
Noma
Shop nowNEW COLLECTION
Objects for slower mornings.
Thoughtful essentials, made in small batches from natural materials.
Explore the collectionOur materials
No. 01 · Hinoki
PLANT-BASEDMADE IN SMALL BATCHESREFILLABLE
- Artifact
- PNG · 1440×900
- Billing
- 1 credit
- Engine
- stable
cURL or Guzzle
Nothing to install beyond what PHP already has.
Shared hosting friendly
No process to keep alive, no binary to install, no memory limit to raise.
Invoices and receipts
format=pdf renders the same Blade or Twig template your users see on screen.
Signed URLs
Put a capture directly in an <img> tag without exposing the ability to change its parameters.
Pricing
One credit per successful capture. Failures and cache hits are free.