Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Screenshot Laravel Package

spatie/laravel-screenshot

Driver-based Laravel package for taking web page screenshots with great defaults. Use Browsershot (Chromium) or Cloudflare Browser Rendering, customize viewport/format/quality, save to files, and easily fake/assert screenshots in tests.

View on GitHub
Deep Wiki
Context7

title: Custom drivers weight: 4

You can create custom screenshot drivers by implementing the ScreenshotDriver interface.

Creating a driver

A screenshot driver must implement two methods:

use Spatie\LaravelScreenshot\Drivers\ScreenshotDriver;
use Spatie\LaravelScreenshot\ScreenshotOptions;

class PlaywrightDriver implements ScreenshotDriver
{
    public function __construct(protected array $config = [])
    {
        // ...
    }

    public function generateScreenshot(
        string $input,
        bool $isHtml,
        ScreenshotOptions $options
    ): string {
        // Take the screenshot and return raw image bytes
    }

    public function saveScreenshot(
        string $input,
        bool $isHtml,
        ScreenshotOptions $options,
        string $path
    ): void {
        // Take the screenshot and save it to $path
    }
}

The $input parameter is either a URL or an HTML string, depending on the value of $isHtml.

The ScreenshotOptions object contains all the rendering options:

  • $options->width — viewport width
  • $options->height — viewport height
  • $options->typeImageType enum (Png, Jpeg, Webp)
  • $options->quality — image quality (0-100, for JPEG/WebP)
  • $options->fullPage — whether to capture the full scrollable page
  • $options->selector — CSS selector to capture
  • $options->clip — clip region (['x' => int, 'y' => int, 'width' => int, 'height' => int])
  • $options->deviceScaleFactor — device pixel ratio
  • $options->omitBackground — whether to omit the background
  • $options->waitForTimeout — milliseconds to wait
  • $options->waitForSelector — CSS selector to wait for
  • $options->waitUntil — network event to wait for

Registering the driver

Register your driver as a singleton in a service provider:

use App\Screenshots\PlaywrightDriver;

// in a service provider

$this->app->singleton('laravel-screenshot.driver.playwright', function () {
    return new PlaywrightDriver(config('laravel-screenshot.playwright', []));
});

Using the driver

Once registered, you can use it per-screenshot:

use Spatie\LaravelScreenshot\Facades\Screenshot;

Screenshot::url('https://example.com')
    ->driver('playwright')
    ->save('screenshot.png');

Or set it as the default in your config file:

// config/laravel-screenshot.php

'driver' => 'playwright',
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport