Skip to content

Laravel Image Presets

On-the-fly image resizing, cropping and format conversion for Laravel, powered by League Glide.

The package registers one GET endpoint (/imagepreset by default). A request names a source image and the transformation in the query string; the first request generates the image and stores it on a filesystem disk, every next request serves the stored file with long-lived cache headers.

  • One endpoint, no setup — the route is registered automatically, without session or CSRF
  • Allowlists — widths, heights, size pairs, qualities, fits and formats a client may request, so the endpoint can’t be used to fill the disk
  • Named presets — thumb, og_image and the like defined once in config
  • Any disk — local or remote (S3, GCS, FTP); optional redirect to a presigned URL
  • Local and remote sources — remote hosts from an allowlist, with SSRF and image-bomb checks
  • SVG — sanitized passthrough, optional rasterization with Imagick
  • Signed URLs and trusted bypass — accept only URLs generated by the backend
  • Cache maintenance — imagepresets:clear, imagepresets:verify for truncated or damaged files
  • Helper, facade and Blade directive — imagepreset_url(), Imagepreset::url(), @imagepreset()
config/imagepresets.php
'presets' => [
'thumb' => ['w' => 300, 'h' => 200, 'fit' => 'crop', 'fm' => 'webp', 'q' => 80],
],
<img src="@imagepreset('images/photo.jpg', 'thumb')" alt="">
<img src="{{ imagepreset_url('images/photo.jpg', ['w' => 600, 'fm' => 'webp']) }}" alt="">
http://example.com/imagepreset?preset=thumb&src=images%2Fphoto.jpg
http://example.com/imagepreset?fm=webp&src=images%2Fphoto.jpg&w=600

Getting started

  1. Installation
  2. Configuration

Usage

  1. Generating URLs
  2. Transformations
  3. Named presets
  4. Allowlists & audit log
  5. Image sources
  6. Storage disks
  7. Drivers & formats
  8. SVG
  9. HTTP caching & CDN
  10. Signed URLs
  11. Trusted bypass
  12. Cache maintenance
  13. Security

Reference

  1. Helper, facade & Blade
  2. Query parameters
  3. Responses
  4. Artisan commands

Upgrading