The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

Capture Web Page Screenshots in Laravel with Spatie's Laravel Screenshot

Last updated on by

Capture Web Page Screenshots in Laravel with Spatie's Laravel Screenshot image

Laravel Screenshot provides a way to capture web page screenshots in Laravel applications. The package uses a driver-based architecture, letting you choose between Browsershot (Chromium) or Cloudflare Browser Rendering depending on your infrastructure.

Main Features

Laravel Screenshot includes the following capabilities:

  • Driver support - Choose between Browsershot (Chromium via Node.js) or Cloudflare Browser Rendering API
  • Default settings - 1280x800 viewport, 2x device scale factor (retina), PNG format, waits for network idle
  • Customizable dimensions and quality - Adjust viewport width, height, and image quality per screenshot
  • Queued background processing - Generate screenshots asynchronously with callback support
  • Testing utilities - Fake mode and assertion helpers for testing screenshot generation
  • Disk storage options - Save screenshots to any configured Laravel filesystem disk

The package supports two drivers. The default Browsershot driver requires Node.js and a Chrome/Chromium binary installed on your server. The Cloudflare driver requires a Cloudflare account with Browser Rendering API access but does not need Node.js or Chrome.

Basic Screenshot Capture

Use the Screenshot facade to capture a web page:

use Spatie\LaravelScreenshot\Facades\Screenshot;
 
Screenshot::url('https://example.com')->save('screenshot.png');

This captures the page at 1280x800 resolution and saves it as a PNG file.

Customizing Dimensions and Quality

Adjust viewport dimensions and image quality using method chaining:

Screenshot::url('https://example.com')
->width(1920)
->height(1080)
->quality(80)
->save('screenshot.jpg');

The quality parameter accepts values from 0-100 and applies when saving as JPEG.

Queued Background Processing

Generate screenshots in the background using saveQueued():

Screenshot::url('https://example.com')
->saveQueued('screenshot.png')
->then(fn (string $path, ?string $diskName) =>
Mail::to($user)->send(new ScreenshotMail($path))
);

The then() callback receives the saved file path and disk name after the screenshot completes.

Testing Screenshot Generation

This package also includes testing utilities for verifying screenshot generation without actually capturing images:

Screenshot::fake();
 
$this->get(route('screenshot'))->assertOk();
 
Screenshot::assertSaved(function ($screenshot) {
return $screenshot->url === 'https://example.com';
});

This prevents external HTTP calls and file system writes during tests while still asserting that screenshot operations were attempted.

Example Use Cases

  • PDF generation workflows
  • Open Graph image generation
  • Web monitoring and archival
  • Visual regression testing
  • Report generation

To learn more about Laravel Screenshot, visit the GitHub repository or read the official documentation.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell

The latest

View all →
Typed Objects for Eloquent with Expressive image

Typed Objects for Eloquent with Expressive

Read article
Malware Blocking and Dependency Policies in Composer 2.10 image

Malware Blocking and Dependency Policies in Composer 2.10

Read article
Aegis for Laravel: Scaffolding and Validation Helpers for Value Objects image

Aegis for Laravel: Scaffolding and Validation Helpers for Value Objects

Read article
Playa: Cookie-Based Temporary Players for Laravel image

Playa: Cookie-Based Temporary Players for Laravel

Read article
Scheduler Attributes and Listener Discovery Control in Laravel 13.12.0 image

Scheduler Attributes and Listener Discovery Control in Laravel 13.12.0

Read article
The PHP Foundation Launches an Ecosystem Security Team image

The PHP Foundation Launches an Ecosystem Security Team

Read article