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
succeeded
https://example.com
Noma
Shop now
NEW COLLECTION

Objects for slower mornings.

Thoughtful essentials, made in small batches from natural materials.

Explore the collection
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.

Free
$0
100 credits
Basic
$10
2,000 credits
Growth
$47
10,000 credits
All plans

Questions this raises

Can I generate PDFs from a Blade template?

Yes — render the template to HTML, POST it with format=pdf, and you get the PDF back.

How do I use it in an img tag?

Sign the query string with your signing secret and put the signed URL in src. Whoever views the page cannot change its parameters.

Does it need PHP 8?

No. Any version with cURL works; the samples use modern syntax for readability.