Guides · PHP · cURL extension

Capture very tall pages as numbered tiles in PHP with cURL extension

A single image has a height cap (20,000 CSS px) because somewhere past that, image viewers and memory both give up. "tile": true is the opt-in for pages that run past it: instead of cutting the capture off, the API returns a ZIP of numbered PNG tiles that cover the entire document.

Below is a complete, runnable PHP program using cURL extension, no third-party dependency needed. It reads your API key from the SNAPDOK_KEY environment variable — free keys take about thirty seconds and need no card.

<?php
$body = json_encode([
    'url' => "https://your-app.com/changelog",
    'format' => "png",
    'full_page' => true,
    'tile' => true,
]);

$ch = curl_init("https://snapdok.io/v1/render");
$headers = [];
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 90,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('SNAPDOK_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_HEADERFUNCTION => function ($ch, $line) use (&$headers) {
        $parts = explode(':', $line, 2);
        if (count($parts) === 2) $headers[strtolower(trim($parts[0]))] = trim($parts[1]);
        return strlen($line);
    },
]);

$bytes = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

if ($status !== 200) {
    throw new RuntimeException("snapdok error $status: $bytes");
}
file_put_contents('page-tiles.zip', $bytes);
echo ($headers['x-tiles'] ?? '?') . " // how many parts are in the ZIP\n";

The tiles overlap on purpose: each part starts 80 px above where the previous one ended, so the seam appears in both images and nothing can fall into a gap — line up the repeated rows and you have the whole page. The archive includes a README stating each part's y-range, and the response carries the numbers too: X-Tiles (count), X-Tile-Overlap (the 80 px), and X-Page-Height.

Note the response type changes: with tiling you receive application/zip, not image/png — code that assumes an image must branch on Content-Type. Pages short enough for one image return a plain PNG even with tile set, so the branch is required, not theoretical. That asymmetry is deliberate: a screenshot is one image to almost everyone, so the archive only happens when you asked for it and the page needs it.

Same endpoint, one more trick: if the page you are rendering has a form on it, adding "pdf_forms": true to a PDF render brings it back with real, fillable AcroForm fields — a PDF people can type into, not a picture of one. How that works.

Notes for cURL extension

Plain ext-curl, no Composer needed. The details that bite: CURLOPT_RETURNTRANSFER must be set or the bytes are echoed to stdout instead of returned; the HTTP status has to be read explicitly with curl_getinfo() because cURL happily "succeeds" on a 401; and response headers need a CURLOPT_HEADERFUNCTION callback if you want to check things like X-Form-Fields. file_put_contents is binary-safe in PHP — strings are byte arrays — so no "b" flag dance is needed.

Response headers worth reading

HeaderMeaning
Content-Typeapplication/zip when tiled, image/png when not needed.
X-TilesNumber of parts in the archive.
X-Tile-OverlapVertical overlap between parts, in CSS px.

Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.

Related guides

Same task, other stacks

More with PHP + cURL extension