PHPackages                             jacksleight/statamic-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/statamic-raster

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

jacksleight/statamic-raster
===========================

0.5.0(7mo ago)455↓75%PHPPHP ^8.1|^8.2|^8.3

Since Nov 15Pushed 5mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (2)Versions (13)Used By (0)

Raster
======

[](#raster)

Rasterise views and partials to images by simply adding a tag 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/statamic-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="statamic-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 `raster`, but you can change it in the config file.

```
{{# resources/views/raster.antlers.html #}}

        Raster
        {{ vite src="resources/css/app.css" }}

        {{ $template_content }}

```

### Automatic Mode

[](#automatic-mode)

To make a view rasterizeable simply implement the main `raster` tag and then generate a URL to your image using the `raster:url` tag.

```
{{# resources/views/blog/hero.antlers.html #}}
{{ %raster
    width="1000"
}}

    ...
    {{ $post:title }}
    {{ $post:date }}

```

```
{{# resources/views/blog/show.antlers.html #}}
{{ push:head }}

{{ /push:head }}
```

The current content will be detected automatically and its data passed to the view. You can override this by adding a `:content="entry_id"` attribute to the URL tag.

You can set [options](#options) with the main tag or through the URL with URL tag. The options passed in the URL take priority over options set in the main tag.

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

> 🚨 **Important:** Views rasterised using automatic mode must implement the raster tag.

### 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` tag.

```
{{# resources/views/blog/hero.antlers.html #}}

    ...
    {{ $post:title }}
    {{ $post:date }}

```

```
/* routes/web.php */
use JackSleight\StatamicRaster\Raster;
use Statamic\Facades\Entry;

Route::get('/blog/{entry}/hero', function (Request $request, $entry) {
    return Raster::make('blog.hero')
        ->content(Entry::find($entry))
        ->width(1000);
})->name('blog.hero');
```

```
{{# resources/views/layout.antlers.html #}}

```

> 🚨 **Important:** Views rasterised using manual mode must not implement the raster tag.

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:

```
 $raster,
] | classes }}>

```

Options
-------

[](#options)

The following options can be set with the main tag or URL tag:

- **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 factor 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.
- **content (string)**
    ID of the entry data to pass to the view.
- **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 main tag or by chaining methods on to the object. The `cache_id` 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.
- **cache\_id (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/c5359e4b9ad8fe604f187f911cc40d9117a3bd36ae1c3f072c80fc70a482fa45/68747470733a2f2f6a61636b736c65696768742e6465762f6173736574732f7061636b616765732f73746174616d69632d7261737465722f76696577706f72742d62617369732e6a7067)](https://camo.githubusercontent.com/c5359e4b9ad8fe604f187f911cc40d9117a3bd36ae1c3f072c80fc70a482fa45/68747470733a2f2f6a61636b736c65696768742e6465762f6173736574732f7061636b616765732f73746174616d69632d7261737465722f76696577706f72742d62617369732e6a7067)

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.

Live Preview
------------

[](#live-preview)

To add a rasterised view to Statamic's live preview add an additional preview target to the collection config with the following URL. If you need to adjust the preview you can add additional options as query parameters.

```
/!/raster/your.view.name

```

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

[](#security--url-signing)

Only views that implement the `raster` tag 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\StatamicRaster\Raster;

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

Sponsoring
----------

[](#sponsoring)

This addon 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

38

—

LowBetter than 85% of packages

Maintenance68

Regular maintenance activity

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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 ~36 days

Recently: every ~78 days

Total

10

Last Release

227d 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 (65 commits)")

### Embed Badge

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

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

###  Alternatives

[statamic/ssg

Generate static sites with Statamic.

254302.4k](/packages/statamic-ssg)[statamic/seo-pro

65440.7k](/packages/statamic-seo-pro)[jacksleight/statamic-bard-texstyle

17172.5k](/packages/jacksleight-statamic-bard-texstyle)[visuellverstehen/statamic-classify

A useful helper to add CSS classes to all HTML tags generated by the bard editor.

20116.8k](/packages/visuellverstehen-statamic-classify)[marcorieser/statamic-livewire

A Laravel Livewire integration for Statamic.

2381.5k10](/packages/marcorieser-statamic-livewire)[withcandour/aardvark-seo

Save time and get your Statamic site to rank better with the SEO addon for Statamic.

13128.3k](/packages/withcandour-aardvark-seo)

PHPackages © 2026

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