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
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
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
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 →
Capture Web Page Screenshots in Laravel with Spatie's Laravel Screenshot image

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

Read article
Nimbus: An In-Browser API Testing Playground for Laravel image

Nimbus: An In-Browser API Testing Playground for Laravel

Read article
Laravel 12.51.0 Adds afterSending Callbacks, Validator whenFails, and MySQL Timeout image

Laravel 12.51.0 Adds afterSending Callbacks, Validator whenFails, and MySQL Timeout

Read article
Handling Large Datasets with Pagination and Cursors in Laravel MongoDB image

Handling Large Datasets with Pagination and Cursors in Laravel MongoDB

Read article
Driver-Based Architecture in Spatie's Laravel PDF v2 image

Driver-Based Architecture in Spatie's Laravel PDF v2

Read article
Why Your Livewire Dashboard Jumps (And How to Fix It) - Laravel In Practice EP18 image

Why Your Livewire Dashboard Jumps (And How to Fix It) - Laravel In Practice EP18

Read article