mehdismekouar / laravel-glide-helper
A Laravel helper for image manipulation using Spatie Glide
Fund package maintenance!
mehdismekouar
Installs: 2
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/mehdismekouar/laravel-glide-helper
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0|^12.0
- spatie/laravel-glide: ^3.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-10-20 14:22:30 UTC
README
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 mehdismekouar/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.1+
- Laravel 10+
spatie/laravel-glidepackage (automatically installed)
Credits
- Mehdi Mekouar
- Built on top of Spatie Laravel Glide
License
The MIT License (MIT). Please see License File for more information.