Menu
Official SDKv1.x

PHP SDK

Official PHP SDK for SnapSharp. Capture screenshots, OG images, and site audits with Composer.

Installation

Install the PHP SDK using your package manager:

shell
composer require snapsharp/sdk

Then import and initialise the client:

php
use SnapSharp\SnapSharp;

$snap = new SnapSharp('sk_live_...');

Replace sk_live_... with your API key from the dashboard.

Quick Start

Three common use cases to get you up and running in minutes.

1. Take a Screenshot

Capture a screenshot and save the result to a file.

php
<?php
require_once 'vendor/autoload.php';

use SnapSharp\SnapSharp;

$snap = new SnapSharp('sk_live_...');

$image = $snap->screenshot('https://example.com', [
    'width' => 1280,
    'height' => 720,
    'format' => 'png',
    'fullPage' => false,
]);

file_put_contents('screenshot.png', $image);
echo "Screenshot saved!\n";

2. Generate an OG Image

Create Open Graph images for social media sharing.

php
<?php
use SnapSharp\SnapSharp;

$snap = new SnapSharp('sk_live_...');

$og = $snap->ogImage('https://example.com', [
    'template' => 'default',
    'width' => 1200,
    'height' => 630,
]);

file_put_contents('og-image.png', $og);

3. Render HTML to Image

Convert an HTML string to a rendered image.

php
<?php
use SnapSharp\SnapSharp;

$snap = new SnapSharp('sk_live_...');

$image = $snap->htmlToImage('<h1>Hello World</h1><p>Rendered with SnapSharp</p>', [
    'width' => 800,
    'height' => 400,
    'format' => 'png',
    'css' => 'body { font-family: sans-serif; background: #1a1a2e; color: #fff; display: grid; place-items: center; }',
]);

file_put_contents('html-render.png', $image);

API Reference

Complete list of methods available on the PHP client.

screenshot()

screenshot(string $url, array $options = []): string

Captures a screenshot of the given URL. Options include width, height, format, fullPage, device, darkMode, delay, and headers.

ogImage()

ogImage(string $url, array $options = []): string

Generates an Open Graph image for the URL using built-in or custom templates.

htmlToImage()

htmlToImage(string $html, array $options = []): string

Renders raw HTML/CSS markup into an image binary string. Supports inline styles and custom viewport.

siteAudit()

siteAudit(string $url, array $options = []): array

Runs a performance and SEO audit. Returns an associative array with scores and recommendations.

All methods that return images accept an optional format parameter ("png", "jpeg", "webp"). Default is "png". See the full API reference for every available option.

Error Handling

The SDK throws typed errors with HTTP status, message, and a unique request ID for debugging. Always wrap calls in a try/catch to handle rate limits and authentication errors gracefully.

php
<?php
use SnapSharp\SnapSharp;
use SnapSharp\Exceptions\SnapSharpException;

$snap = new SnapSharp('sk_live_...');

try {
    $image = $snap->screenshot('https://example.com');
} catch (SnapSharpException $e) {
    echo "Error {$e->getStatus()}: {$e->getMessage()}\n";
    echo "Request ID: {$e->getRequestId()}\n";

    if ($e->getStatus() === 401) {
        echo "Invalid API key. Check your credentials.\n";
    }
    if ($e->getStatus() === 429) {
        echo "Rate limited. Retry after: {$e->getRetryAfter()}s\n";
    }
}
StatusMeaningAction
400Bad Request — invalid parametersCheck the request body and query params
401Unauthorized — invalid or missing API keyVerify your API key in the dashboard
429Too Many Requests — rate limit exceededWait for retryAfter seconds
500Internal Server ErrorRetry with exponential back-off

Configuration

Customise the client with optional settings passed at initialisation.

php
$snap = new SnapSharp('sk_live_...', [
    'baseUrl' => 'https://api.snapsharp.dev',  // Custom API base URL
    'timeout' => 30,                            // Request timeout in seconds
    'retries' => 2,                             // Auto-retry on 5xx errors
]);
OptionDefaultDescription
baseUrlapi.snapsharp.devOverride the API base URL (e.g. for on-premise)
timeout30sMaximum time to wait for a response
retries0Number of automatic retries on 5xx errors

SDKs for other languages

Ready to start building?

Get your free API key and start capturing screenshots in under a minute. 100 free screenshots every month — no credit card required.