Quickstart

Website screenshots in PHP

One HTTPS request, cURL, and no browser of your own to keep running.

Renderwolf is a plain HTTPS API, so PHP needs no SDK - cURL is enough. A successful render returns the image bytes directly, with no JSON envelope and no base64, so you write the response straight to a file.

Get a key

Create one in the portal. It is shown once and stored hashed, so put it in an environment variable rather than in the file - the samples below read it from one.

Take a screenshot

<?php
$ch = curl_init('https://api.ironfang.uk/renderwolf/v1/screenshot');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $key,
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'url' => 'https://example.com',
        'width' => 1280,
    ]),
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($status !== 200) {
    $err = json_decode($body, true)['error'];
    throw new RuntimeException("{$err['code']}: {$err['message']}");
}

file_put_contents('shot.png', $body);

Handling errors

Success is binary; every error is JSON, shaped as {"error": {"code", "message"}}. A missing or unknown key is 401 invalid_api_key, and a key without the renderwolf:render scope is 403.

// CURLOPT_RETURNTRANSFER is required. Without it cURL prints the
// binary image to stdout, which in a web request means the PNG bytes
// end up in your HTML response.

PDFs and templates

The same call shape works for /v1/pdf, and for templated images at /v1/image/{id}. Only the path and the body change.

Next