fomvasss / laravel-imagepresets
Image presets (on-the-fly resize/convert) for Laravel via League Glide
Requires
- php: ^8.1
- illuminate/cache: ^10.0|^11.0|^12.0|^13.0
- illuminate/http: ^10.0|^11.0|^12.0|^13.0
- illuminate/routing: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
- league/glide: ^2.0|^3.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
Suggests
- enshrined/svg-sanitize: Full SVG sanitization (XSS protection). Without this package a basic regex sanitizer is applied.
Provides
None
Conflicts
None
Replaces
None
README
On-the-fly image resizing, cropping and format conversion for Laravel, powered by League Glide. One endpoint takes the source and the transformation in the query string, generates the image on the first request, stores it on a filesystem disk and serves the stored file with long-lived cache headers afterwards.
- One auto-registered endpoint — no session, no CSRF, throttled
- Allowlists for sizes, qualities, fits and formats; named presets in config
- Any disk — local, S3, GCS, FTP; optional redirect to a presigned URL
- Local and remote sources with SSRF and image-bomb checks
- WebP, AVIF, JPG, PNG, GIF output; GD or Imagick; HEIC input with Imagick
- SVG — sanitized passthrough or rasterization
- Signed URLs and trusted bypass for backend-generated URLs
imagepresets:clearandimagepresets:verifyfor cache maintenanceimagepreset_url()helper,Imagepresetfacade,@imagepresetBlade directive
Requirements
- PHP ^8.1
- Laravel 10 | 11 | 12 | 13
- league/glide ^2.0 | ^3.0,
ext-gdorext-imagick
Installation
composer require fomvasss/laravel-imagepresets php artisan vendor:publish --tag=imagepresets-config
IMAGEPRESET_PATH=imagepresets
Set
IMAGEPRESET_PATH. With the default empty path generated files land in the root of thepublicdisk, andimagepresets:cleardeletes the whole disk.
Quick start
// 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="">
<img src="/imagepreset?src=images/photo.jpg&w=600&fm=webp" alt="">
Sizes outside the allowlists (allowed_widths, allowed_sizes, …) return 404 — configure them or use presets.
Documentation
Online: https://fomvasss.github.io/laravel-imagepresets/ — the same pages as in docs/.
- Installation · Configuration
- Generating URLs · Transformations · Named presets · Allowlists & audit log
- Image sources · Storage disks · Drivers & formats · SVG
- HTTP caching & CDN · Signed URLs · Trusted bypass · Cache maintenance · Security
- Reference: Helper, facade & Blade · Query parameters · Responses · Artisan commands
- Upgrading · Changelog
Testing
composer test
License
MIT — see LICENSE.
Support
If this package is useful to you, consider supporting its development:
USDT TRC20:
THLgp6DxiAtbNHvgnKV56vk1L38UuUagKf