mehdismekouar/laravel-glide-helper
最新稳定版本:v1.0.0
Composer 安装命令:
composer require mehdismekouar/laravel-glide-helper
包简介
A Laravel helper for image manipulation using Spatie Glide
README 文档
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.
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-20