Laravel 5 intervention-image / intervention-cache: flexible url / routing Laravel 5 intervention-image / intervention-cache: flexible url / routing laravel laravel

Laravel 5 intervention-image / intervention-cache: flexible url / routing


It is simple. You just have to tell Laravel that your image parameter consists of letters, slash, dash, underscore and dot ('[A-Za-z0-9\/\.\-\_]+'), because by default the framework matches everything but the slash /.

Route::get('imager/{image?}', function($src) {    $cachedImage = Image::cache(function($image) use ($src) {        return $image->make($src)->resize(100,100);    }, 1, false);    return Response::make($cachedImage, 200, ['Content-Type' => 'image/jpeg']);})->where('image', '[A-Za-z0-9\/\.\-\_]+');

You can find out more about parameter binding in the documentation.


Now you can now use the URL based image manipulation:

Within a Laravel application it is possible to use the URL to manipulate images dynamically. The manipulated version of the an image will be stored in the cache and will be loaded directly without resource-intensive GD operation.

An image has to be uploaded only once. All manipulations like resizing or cropping will be handled later, when the file is accessed via a HTTP request like this:

http://yourhost.com/{route-name}/{template-name}/{file-name}