How to Get Browser screenshots Using Laravel?
Teams applying “How to Get Browser screenshots Using Laravel?” in a production project can use this useful resource to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.
Before copying the example into a live application, confirm version-specific behaviour with the official Laravel website and test it against the project’s actual database and runtime.
Hello Friends,
This tutorial will teach you how to take a screenshot in Laravel. Here, you will discover how to screenshot a website's url using Laravel. You may comprehend the idea behind how to screenshot a website in Laravel using the url. We'll demonstrate how to snap a screenshot in Laravel with your assistance. Okay, let's get into the specifics.
We will use spatie/browsershot composer package for take a screenshot of website in laravel. we will use url(), setOption(), windowSize(), waitUntilNetworkIdle() and save() method to capture browser screenshot in
Now let's start.
Step 1:Install Laravel Application
This is optional; however, if you have not created the laravel app, then you may go ahead and execute the below command:
composer create-project laravel/laravel example-app
Step 2: Install spatie/browsershot Package
Installing the spatie/browsershot package will enable us to take a snapshot of a URL in Laravel. Let's execute the following commands:
composer require spatie/browsershot
Next, we need to install puppeteer npm package, that used to capture screenshot. let's installed using the below command:
npm install puppeteer --global
Step 3: Create Route
In this is step we need to create one route for capture browser screenshot. let's add the below route on web.php file.
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\DemoController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('demo', [DemoController::class,'index']);
Step 4: Create Controller
We need to create a DemoController with the index() method in this stage.
app/Http/Controllers/DemoController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Spatie\Browsershot\Browsershot;
class DemoController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index(Request $request)
{
Browsershot::url('/')
->setOption('landscape', true)
->windowSize(3840, 2160)
->waitUntilNetworkIdle()
->save('NiceSnippets-IT-Web-Code-Blog-Tutorials.png');
dd("Done");
}
}
Run Laravel App:
All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:
php artisan serve
Output
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial