league/glide
Glide is an on-demand PHP image manipulation library with an HTTP API. Resize, crop, and apply effects, then cache results with far-future headers. Works with GD, Imagick, or libvips, integrates with Flysystem, and can sign URLs for security.
If your application uses the Laravel framework, you can use the LaravelResponseFactory. Since Laravel uses HttpFoundation under the hood, this adapter actually extends the Symfony adapter.
composer require league/glide-laravel
<?php
use League\Glide\ServerFactory;
use League\Glide\Responses\LaravelResponseFactory;
$server = ServerFactory::create([
'response' => new LaravelResponseFactory(app('request'))
]);
Here is a fully functioning example of how to get Glide up and running with Laravel really quick. First, create a new entry in your routes file:
<?php
Route::get('/img/{path}', 'ImageController@show')->where('path', '.*');
Next, create a controller that will serve all your Glide images. This will use the default Laravel storage path (/storage/app) for the source images.
<?php
namespace App\Http\Controllers;
use Illuminate\Contracts\Filesystem\Filesystem;
use League\Glide\Responses\LaravelResponseFactory;
use League\Glide\ServerFactory;
class ImageController extends Controller
{
public function show(Filesystem $filesystem, $path)
{
$server = ServerFactory::create([
'response' => new LaravelResponseFactory(app('request')),
'source' => $filesystem->getDriver(),
'cache' => $filesystem->getDriver(),
'cache_path_prefix' => '.cache',
'base_url' => 'img',
]);
return $server->getImageResponse($path, request()->all());
}
}
How can I help you explore Laravel packages today?