This package provides a simple way to take screenshots of web pages in Laravel apps. It uses a driver-based architecture, so you can choose between different screenshot backends:
Screenshots are taken with beautiful defaults: 1280x800 viewport, 2x device scale factor (retina), PNG format, and waiting for network idle.
Here's a quick example:
use Spatie\LaravelScreenshot\Facades\Screenshot;
Screenshot::url('https://example.com')->save('screenshot.png');
You can customize the viewport, format, and capture options:
use Spatie\LaravelScreenshot\Facades\Screenshot;
Screenshot::url('https://example.com')
->width(1920)->height(1080)
->quality(80)
->save('screenshot.jpg');
You can queue screenshot generation for background processing:
use Spatie\LaravelScreenshot\Facades\Screenshot;
Screenshot::url('https://example.com')
->saveQueued('screenshot.png')
->then(fn (string $path, ?string $diskName) => Mail::to($user)->send(new ScreenshotMail($path)));
You can also test your screenshots:
use Spatie\LaravelScreenshot\Facades\Screenshot;
it('can take a screenshot', function () {
Screenshot::fake();
$this->get(route('screenshot'))->assertOk();
Screenshot::assertSaved(function ($screenshot) {
return $screenshot->url === 'https://example.com';
});
});
##We got badges
