spatie/laravel-image-optimizer
Laravel integration for spatie/image-optimizer. Optimize PNG, JPG, SVG, and GIF files by running them through available system binaries. Use the ImageOptimizer facade, resolve an OptimizerChain from the container, or apply middleware to optimize uploads automatically.
jpegoptim over guetzli based on system availability). This aligns with modern Laravel’s emphasis on modularity and extensibility.spatie/image-optimizer, which supports multiple optimization tools (e.g., pngquant, svgo, cwebp). This reduces vendor lock-in and allows teams to choose tools based on trade-offs (speed vs. compression ratio).imagemagick, libvips) requires minimal PHP-level changes, but server setup (e.g., Docker, shared hosting) may need adjustments.Storage facade (local, S3, etc.), enabling optimization for uploaded files or asset pipelines. Can be extended to work with Flysystem adapters for broader storage support.OptimizeImageJob::dispatch($imagePath);
jpegoptim, optipng). Risks:
Dockerfile.jpegoptim, pngquant, etc.) available in all target environments (dev, staging, prod)?Dockerfile?image-optimized-<hash>.jpg)?Dockerfile.imagick or gd).spatie/laravel-image-optimizer + intervention/image.config/image-optimizer.php.Model Observers or HasManyThrough events.class Product extends Model
{
protected static function booted()
{
static::saved(function ($product) {
if ($product->wasChanged('image_path')) {
OptimizeImageJob::dispatch($product->image_path);
}
});
}
}
public function handle(Request $request, Closure $next)
{
$path = storage_path('app/public/' . $request->path());
if (ImageOptimizer::shouldOptimize($path)) {
ImageOptimizer::optimize($path);
}
return $next($request);
}
spatie/image-optimizer).Storage::disk('s3')->path() and optimize locally before re-uploading.guetzli (Google’s JPEG encoder) may require additional setup.spatie/laravel-image-optimizer and spatie/image-optimizer for updates.jpegoptim) may require manual updates in containers or servers.jpegoptim quality settings).Spatie\ImageOptimizer\OptimizerChain::getAvailableTools() to verify tool detection.How can I help you explore Laravel packages today?