PHP

Take screenshots using PHP with our official SDK or plain HTTP requests.

Installation

composer require lambdashot/lambdashot-php

Quick Start

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

use LambdaShot\Client;

$client = new Client('YOUR_ACCESS_KEY', 'YOUR_SECRET_KEY');

// Take a screenshot
$screenshot = $client->take([
    'url' => 'https://example.com',
    'format' => 'png',
    'viewport_width' => 1920,
    'viewport_height' => 1080,
]);

// Save to file
file_put_contents('screenshot.png', $screenshot);

Generate Signed URL

$url = $client->generateSignedUrl([
    'url' => 'https://example.com',
    'format' => 'png',
    'block_ads' => true,
]);

echo $url;
// https://api.lambdashot.com/take?url=...&signature=...

Options

$screenshot = $client->take([
    'url' => 'https://example.com',

    // Output
    'format' => 'png',
    'image_quality' => 90,

    // Viewport
    'viewport_width' => 1920,
    'viewport_height' => 1080,
    'viewport_device' => 'iphone_15_pro',

    // Full page
    'full_page' => true,
    'full_page_scroll' => true,

    // Blocking
    'block_ads' => true,
    'block_cookie_banners' => true,
    'block_trackers' => true,

    // Customization
    'dark_mode' => true,
    'delay' => 2,
]);

Without SDK (cURL)

<?php
$params = http_build_query([
    'access_key' => 'YOUR_ACCESS_KEY',
    'url' => 'https://example.com',
    'format' => 'png',
    'viewport_width' => 1920,
]);

$ch = curl_init("https://api.lambdashot.com/take?{$params}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$screenshot = curl_exec($ch);
curl_close($ch);

file_put_contents('screenshot.png', $screenshot);

Video Recording

$video = $client->animate([
    'url' => 'https://example.com',
    'scenario' => 'scroll',
    'duration' => 10,
    'format' => 'mp4',
]);

file_put_contents('video.mp4', $video);

Error Handling

use LambdaShot\Exception\LambdaShotException;

try {
    $screenshot = $client->take(['url' => 'https://example.com']);
} catch (LambdaShotException $e) {
    if ($e->getCode() === 'timeout_error') {
        echo "Screenshot timed out, retrying...";
    } else {
        echo "Error: " . $e->getMessage();
    }
}

Laravel Integration

// config/services.php
'lambdashot' => [
    'access_key' => env('LAMBDASHOT_ACCESS_KEY'),
    'secret_key' => env('LAMBDASHOT_SECRET_KEY'),
],

// App/Providers/AppServiceProvider.php
use LambdaShot\Client;

public function register()
{
    $this->app->singleton(Client::class, function ($app) {
        return new Client(
            config('services.lambdashot.access_key'),
            config('services.lambdashot.secret_key')
        );
    });
}

// In your controller
public function screenshot(Client $lambdashot)
{
    $screenshot = $lambdashot->take([
        'url' => 'https://example.com',
        'format' => 'png',
    ]);

    return response($screenshot)
        ->header('Content-Type', 'image/png');
}