PHPackages                             jacksleight/laravel-raster - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jacksleight/laravel-raster

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jacksleight/laravel-raster
==========================

0.5.0(10mo ago)1266↓75%1PHPPHP ^8.1|^8.2|^8.3

Since Nov 15Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/jacksleight/laravel-raster)[ Packagist](https://packagist.org/packages/jacksleight/laravel-raster)[ GitHub Sponsors](https://github.com/jacksleight)[ RSS](/packages/jacksleight-laravel-raster/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (10)Used By (1)

Raster
======

[](#raster)

Rasterise views and components to images by simply adding a directive and fetching the URL. Automatic routing, scaling, caching, protection and preview mode. Zero configuration (unless you need it).

Installation
------------

[](#installation)

Run the following command from your project root:

```
composer require jacksleight/laravel-raster
```

This package uses [Puppeteer](https://pptr.dev/) via [spatie/browsershot](https://spatie.be/docs/browsershot/v4/introduction) under the hood, you will also need follow the necessary Puppeteer [installation steps](https://spatie.be/docs/browsershot/v4/requirements) for your system. I can't help with Puppeteer issues or rendering inconsistencies, sorry.

If you need to customise the config you can publish it with:

```
php artisan vendor:publish --tag="raster-config"
```

Usage
-----

[](#usage)

### Layout Setup

[](#layout-setup)

The views will be rendered inside a layout view where you can load any required CSS and other assets. By default this is a component called `layouts.raster`, but you can change it in the config file.

```
{{-- resources/views/components/layouts/raster.blade.php --}}

        Raster
        @vite(['resources/css/app.css'])

        {{ $slot }}

```

### Automatic Mode

[](#automatic-mode)

To make a view rasterizeable simply implement the `@raster` directive and then generate a URL to your image using the `raster()` helper. The data closure receives any parameters passed in the URL and should return an array of data to pass to the view.

```
{{-- resources/views/blog/hero.blade.php --}}
@raster(
    width: 1000,
    data: fn ($post) => [
        'post' => Post::find((int) $post),
    ],
)

    ...
    {{ $post->title }}
    {{ $post->date }}

```

```
{{-- resources/views/blog/show.blade.php --}}
@push('head')

@endpush
```

You can set [options](#options) with the directive or through the URL by chaining methods on to the helper. The options passed in the URL take priority over options set in the directive.

When the view is rendered during normal non-raster requests the directive does nothing.

Important

Views rasterised using automatic mode must implement the raster directive.

### Manual Mode

[](#manual-mode)

If you would like more control over the routing and how the requests are handled you can define your own routes that return raster responses and then generate a URL to your image using the usual `route()` helper.

```
{{-- resources/views/blog/hero.blade.php --}}

    ...
    {{ $post->title }}
    {{ $post->date }}

```

```
/* routes/web.php */
use JackSleight\LaravelRaster\Raster;

Route::get('/blog/{post}/hero', function (Post $post) {
    return Raster::make('blog.hero')
        ->data(['post' => $post])
        ->width(1000);
})->name('blog.hero');
```

```
{{-- resources/views/layout.blade.php --}}

```

Important

Views rasterised using manual mode must not implement the raster directive.

Customising Rasterised Views
----------------------------

[](#customising-rasterised-views)

If you would like to make changes to the view based on whether or not it's being rasterised you can check for the `$raster` variable:

```
class([
    'rounded-none' => $raster ?? null,
]) }}>

```

Options
-------

[](#options)

The following options can be set with the directive or by chaining methods on to the object:

- **width (int)**
    Width of the generated image.
- **height (int, auto)**
    Height of the generated image.
- **basis (int)**
    [Viewport basis](#viewport-basis) of the generated image.
- **scale (int, 1)**
    Scale of the generated image.
- **type (string, png)**
    Type of the generated image (`png`, `jpeg` or `pdf`).
- **file (string)**
    File name of the response, excluding extension.
- **data (array)**
    Array of data to pass to the view.
- **preview (bool, false)**
    Enable [preview mode](#preview-mode).

With PDF output a height is required, it will only contain one page, and dimensions are still pixels not mm/inches. If you're looking to generate actual documents from views I highly recommend checking out [spatie/laravel-pdf](https://github.com/spatie/laravel-pdf).

### Caching

[](#caching)

The following caching options can be set with the directive or by chaining methods on to the object. The `cacheId` cannot be passed as a URL parameter. You can globally disable caching by setting the `RASTER_CACHE_ENABLED` env var to `false`. By default the cache will be stored locally in `storage/app/raster`, you can change this by setting the `RASTER_CACHE_DISK` and `RASTER_CACHE_PATH` env vars.

- **cache (bool, false)**
    Enable caching of generated images.
- **cacheId (string, '\_')**
    Cache identifier (optional, see below).

File paths will use this pattern: `[cache_path]/[view_name]/[cache_id]/[params_hash].[extension]`.

Viewport Basis
--------------

[](#viewport-basis)

When the basis option is set the image will be generated as if the viewport was that width, but the final image will match the desired width. Here's an example of how that affects output:

[![Viewport Basis](https://camo.githubusercontent.com/9ef8cfb122b5e9ef549f79583b95b2ecb3f0f1133cbe4e3d16763bbb1af6fc0c/68747470733a2f2f6a61636b736c65696768742e6465762f6173736574732f7061636b616765732f6c61726176656c2d7261737465722f76696577706f72742d62617369732e6a7067)](https://camo.githubusercontent.com/9ef8cfb122b5e9ef549f79583b95b2ecb3f0f1133cbe4e3d16763bbb1af6fc0c/68747470733a2f2f6a61636b736c65696768742e6465762f6173736574732f7061636b616765732f6c61726176656c2d7261737465722f76696577706f72742d62617369732e6a7067)

Preview Mode
------------

[](#preview-mode)

In preview mode the HTML will be returned from the response but with all the appropriate scaling applied. This gives you a 1:1 preview without the latency that comes from generating the actual image.

Security &amp; URL Signing
--------------------------

[](#security--url-signing)

Only views that implement the `@raster` directive can be rasterised in automatic mode, an error will be thrown before execution if they don't. It's also recommended to enable URL signing on production to ensure they can't be tampered with. You can do this by setting the `RASTER_SIGN_URLS` env var to `true`.

Customising Browsershot
-----------------------

[](#customising-browsershot)

If you need to customise the Browsershot instance you can pass a closure to `Raster::browsershot()` in a service provider:

```
use JackSleight\LaravelRaster\Raster;

Raster::browsershot(fn ($browsershot) => $browsershot
    ->setOption('args', ['--disable-web-security'])
    ->waitUntilNetworkIdle()
);
```

Sponsoring
----------

[](#sponsoring)

This package is completely free to use. However fixing bugs, adding features and helping users takes time and effort. If you find this useful and would like to support its development any [contribution](https://github.com/sponsors/jacksleight) would be greatly appreciated. Thanks! 🙂

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance54

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~29 days

Recently: every ~53 days

Total

9

Last Release

315d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b1acb404d9801e5f633e31efa3403a4735e43ea93c798e3f895ba3264c92c6e?d=identicon)[jacksleight](/maintainers/jacksleight)

---

Top Contributors

[![jacksleight](https://avatars.githubusercontent.com/u/126740?v=4)](https://github.com/jacksleight "jacksleight (53 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jacksleight-laravel-raster/health.svg)

```
[![Health](https://phpackages.com/badges/jacksleight-laravel-raster/health.svg)](https://phpackages.com/packages/jacksleight-laravel-raster)
```

###  Alternatives

[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4205.3M84](/packages/livewire-volt)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
