league/glide
Glide is an on-demand PHP image manipulation library served over HTTP. Resize, crop, and apply effects with simple URL parameters, with automatic caching and far-future headers. Works with GD, Imagick, or libvips and Flysystem storage.
GlideMiddleware) or a service provider for centralized image handling. Leverages Laravel’s dependency injection (DI) for Server configuration./tenant1/uploads/) enables tenant isolation without per-tenant Glide instances.Illuminate\Http\Request and Symfony\Component\HttpFoundation\Response.Storage facade via Flysystem adapters (e.g., local, s3, gcs).glide:process job for async resizing).| Risk Area | Mitigation Strategy |
|---|---|
| Performance | Benchmark imagick vs. libvips vs. gd for target workloads. Use libvips for high-res images. |
| Cache Invalidation | Implement ETag/Last-Modified headers for cache busting. Use Laravel’s Cache facade for metadata. |
| Security | Enforce HTTP signatures for private images. Validate w/h params to prevent DoS. |
| Dependency Bloat | Audit intervention/image and flysystem for vulnerabilities. Pin versions in composer.json. |
| Cold Starts | Pre-warm cache for critical images (e.g., via Laravel’s booted event). |
League\Glide\Api\Manipulator interface.Cache-Control headers accordingly.| Component | Laravel Integration Strategy |
|---|---|
| Routing | Middleware (GlideMiddleware) or route group (Route::glide()). |
| Storage | Use Laravel’s Storage facade with Flysystem adapters (e.g., Storage::disk('s3')->path()). |
| Caching | Disk cache (default) or Redis (League\Flysystem\Cache\Redis). |
| HTTP Layer | PSR-7/PSR-15 compatible. Works with Laravel’s Illuminate\Http\Request. |
| Async Processing | Offload to Laravel Queues (e.g., glide:resize job). |
| Monitoring | Log image processing metrics (e.g., duration, failures) via Laravel’s Log facade. |
exec_time, cache hit ratio).gd with libvips for high-res images.symfony/http-foundation.gd, imagick, or libvips (prioritize libvips for performance).exif (for or=auto).league/flysystem: For storage abstraction.intervention/image: For core image manipulation (v2.7+ recommended).// app/Providers/GlideServiceProvider.php
public function register()
{
$this->app->singleton(Server::class, function ($app) {
return ServerFactory::create([
'source' => $app->storagePath('app/public/images'),
'cache' => $app->storagePath('app/public/glide-cache'),
'base_url' => 'img/glide',
'driver' => 'libvips', // or 'imagick', 'gd'
]);
});
}
// app/Http/Middleware/GlideMiddleware.php
public function handle(Request $request, Closure $next)
{
$server = app(Server::class);
$path = $request->path();
$query = $request->query();
return $server->outputImage($path, $query);
}
// routes/web.php
Route::middleware(['glide'])->prefix('img/glide')->get('{path}', function () {
// Handled by middleware
});
<img src="/img/glide/photos/landscape.jpg?w=800&h=600&fit=crop">
league/glide for breaking changes (e.g., API deprecations).Log facade.try {
$server->outputImage($path, $query);
} catch (\Exception $e) {
Log::error("Glide processing failed for {$path}: {$e->getMessage()}");
abort(500);
}
glide-cache) can be ephemeral but source images must be backed up.source path and base_url configuration.gd, imagick) and permissions.XHProf; optimize with libvips.debug: true in ServerFactory for verbose logs.dd($server->getManipulations($path, $query)) to inspect transformations.max_memory_limit for large images (e.g., ini_set('memory_limit', '512M')).libvips for memory-efficient processing.How can I help you explore Laravel packages today?