Plain PHP with cURL
<?php
$url = 'https://api.aisnapapi.com/v1/screenshot?url=' . urlencode('https://example.com');
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY'],
]);
$png = curl_exec($ch);
file_put_contents('shot.png', $png);
Even shorter: file_get_contents
<?php
$ctx = stream_context_create(['http' => [
'header' => "Authorization: Bearer YOUR_API_KEY\r\n",
]]);
$png = file_get_contents(
'https://api.aisnapapi.com/v1/screenshot?url=' . urlencode('https://example.com'),
false, $ctx
);
file_put_contents('shot.png', $png);
Laravel: stream a screenshot to the browser
<?php
use Illuminate\Support\Facades\Http;
Route::get('/screenshot', function () {
$res = Http::withToken(env('SNAPAPI_KEY'))
->get('https://api.aisnapapi.com/v1/screenshot', [
'url' => request('url'),
'full_page' => true,
]);
return response($res->body(), $res->status())
->header('Content-Type', 'image/png');
});
Guzzle (any framework)
<?php
use GuzzleHttp\Client;
$client = new Client();
$res = $client->get('https://api.aisnapapi.com/v1/screenshot', [
'query' => ['url' => 'https://example.com', 'format' => 'pdf'],
'headers' => ['Authorization' => 'Bearer YOUR_API_KEY'],
]);
file_put_contents('page.pdf', $res->getBody());
Common gotchas
- Always
urlencode() the target URL. Otherwise a & in the URL will break the query string.
- Single-page apps: if a React or Vue page renders blank, add
&delay=1500.
- Don't load the whole image into memory if you're proxying it — use
CURLOPT_FILE with a stream, or Laravel's streamed responses.
- WordPress: the same plain-PHP example works inside a plugin or theme; just store the key in
wp-config.php as a constant.