Code review at scale is broken. Here’s how Augment Code is fixing it.

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
Tinkerwell logo

Tinkerwell

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

Tinkerwell
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
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
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
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

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

Shift
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

The latest

View all →
Inertia v3 Upgrade Prompt and JSON Log Support in Laravel Boost v2.3.0 image

Inertia v3 Upgrade Prompt and JSON Log Support in Laravel Boost v2.3.0

Read article
Laracon AU Returns to Brisbane - Call for Speakers Now Open image

Laracon AU Returns to Brisbane - Call for Speakers Now Open

Read article
Detecting and Fixing Race Conditions in Laravel Applications image

Detecting and Fixing Race Conditions in Laravel Applications

Read article
LaraCopilot: Generate Laravel MVPs From a Single Prompt With AI image

LaraCopilot: Generate Laravel MVPs From a Single Prompt With AI

Read article
Model::withoutRelation() in Laravel 12.54.0 image

Model::withoutRelation() in Laravel 12.54.0

Read article
Tyro Checkpoint: Instant SQLite Snapshots for Laravel Local Development image

Tyro Checkpoint: Instant SQLite Snapshots for Laravel Local Development

Read article