laravel-glide-helper maintained by digitonma
Description
A Laravel helper for image manipulation using Spatie Glide
Authors
Last update
2026/08/03 14:45
(dev-main)
License
Downloads
0
Tags
Laravel Glide Helper
A simple Laravel helper function for on-the-fly image manipulation using Spatie Glide.
Features
- 🚀 On-the-fly image manipulation - Resize, crop, and transform images dynamically
- 💾 Automatic caching - Generated images are cached to avoid regeneration
- 🔧 Configurable defaults - Set global parameters for consistent image processing
- 📁 Multiple source support - Works with storage/ and public/ directories
- 🌐 External URL handling - Passes through external URLs unchanged
- ⚡ Performance optimized - Only processes when necessary
Installation
Install the package via Composer:
composer require digitonma/laravel-glide-helper
Optionally, publish the config file:
php artisan vendor:publish --tag="laravel-glide-helper-config"
This is the contents of the published config file:
return [
'defaults' => [
'q' => 90, // Quality (1-100)
'fm' => 'webp', // Format (webp, jpg, png, gif)
'fit' => 'max' // Fit (contain, max, fill, stretch, crop)
],
'output_dir' => 'manipulated', // Directory for cached images
];
Usage
Basic Usage
// In Blade templates
<img src="{{ glide('/storage/photos/image.jpg', ['w' => 300, 'h' => 200]) }}" alt="Resized">
Common Parameters
// Resize
glide($image, ['w' => 300, 'h' => 200])
// Crop to exact dimensions
glide($image, ['w' => 200, 'h' => 200, 'fit' => 'crop'])
// Change format and quality
glide($image, ['fm' => 'webp', 'q' => 85])
// Apply filters
glide($image, ['filt' => 'greyscale', 'blur' => 5])
Supported Parameters
All Glide parameters are supported:
- Size:
w(width),h(height),fit(contain, max, fill, stretch, crop) - Format:
fm(webp, jpg, png, gif),q(quality 1-100) - Effects:
blur,sharp,filt(greyscale)
How It Works
- Path Resolution: Automatically detects if image is in
storage/orpublic/ - Caching: Creates a unique hash based on source file and parameters
- Generation: Uses Spatie Glide to manipulate image only if not cached
- URL Generation: Returns asset URL for the manipulated image
External URLs are passed through unchanged.
Requirements
- PHP 8.3+
- Laravel 12 or 13
spatie/laravel-glidepackage (automatically installed)
Credits
- Abdelhamid Errahmouni
- Mehdi Mekouar
- Built on top of Spatie Laravel Glide
License
The MIT License (MIT). Please see License File for more information.