PHP cURL Laravel WordPress

Screenshot API for PHP

Capture website screenshots in PHP using a simple cURL call or the Guzzle HTTP client. No headless browser installation needed. Works on any shared hosting.

Get Free API Key →

Quick Start with cURL

<?php

$url = "https://grabshot.dev/v1/screenshot?" . http_build_query([
    'url' => 'https://example.com',
    'key' => 'YOUR_API_KEY',
]);

$image = file_get_contents($url);
file_put_contents('screenshot.png', $image);

Full Example with Error Handling

<?php

function captureScreenshot($targetUrl, $options = []) {
    $params = array_merge([
        'url' => $targetUrl,
        'key' => getenv('GRABSHOT_API_KEY'),
        'width' => '1440',
        'format' => 'png',
    ], $options);

    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL => "https://grabshot.dev/v1/screenshot?" . http_build_query($params),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_FOLLOWLOCATION => true,
    ]);

    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($httpCode !== 200) {
        throw new \Exception("Screenshot failed: HTTP $httpCode");
    }

    return $response;
}

// Usage
$img = captureScreenshot('https://github.com', [
    'width' => '1920',
    'fullPage' => 'true',
    'deviceFrame' => 'macbook',
]);
file_put_contents('github.png', $img);

Laravel Integration

// app/Services/ScreenshotService.php
namespace App\Services;

use Illuminate\Support\Facades\Http;

class ScreenshotService
{
    public function capture(string $url, array $options = []): string
    {
        $response = Http::get('https://grabshot.dev/v1/screenshot', array_merge([
            'url' => $url,
            'key' => config('services.grabshot.key'),
        ], $options));

        $response->throw();
        return $response->body();
    }
}

// Usage in a controller:
$screenshot = app(ScreenshotService::class)->capture('https://example.com');
Storage::put('screenshots/example.png', $screenshot);

WordPress Plugin Snippet

// Add to your theme's functions.php or a custom plugin
function grabshot_screenshot($url) {
    $api_url = add_query_arg([
        'url' => $url,
        'key' => get_option('grabshot_api_key'),
        'width' => '1200',
    ], 'https://grabshot.dev/v1/screenshot');

    $response = wp_remote_get($api_url, ['timeout' => 30]);
    
    if (is_wp_error($response)) {
        return false;
    }
    
    return wp_remote_retrieve_body($response);
}

// Shortcode: [grabshot url="https://example.com"]
add_shortcode('grabshot', function($atts) {
    $img = grabshot_screenshot($atts['url']);
    if (!$img) return 'Screenshot unavailable';
    return '<img src="data:image/png;base64,' . base64_encode($img) . '" />';
});

Pricing

Free: 25 screenshots/month. No credit card.

Starter: $9/mo for 2,500 screenshots.

Pro: $29/mo for 10,000 screenshots with AI cleanup.

Start Free — No Credit Card →