Reputation: 5829
I am using the Intervention Image library in my Laravel 5.2 app along with the Image Cache plugin
I have been using the predefined templates out the box with no issues like so:
{{ route('imagecache', ['template' => 'medium', 'filename' => 'image.jpg']) }}"
I have seen in the documentation that as well as the default sizes small, medium and large you can create image filters to create custom manipulations and define them as a template in the config file so that instead of medium I would pass my template name. The documentation references Image filters as a way to do this but it's a bit sketchy as to exactly how to do it. Does anyone know how you do it exactly?
Upvotes: 0
Views: 1555
Reputation: 1804
Inside config/imagecache.php
there is a templates
key, here you can add your own.
For example:
'templates' => [
// ...
'x-large' => 'App\Filters\ExtraLarge',
// ...
],
Then you would just need to create the class App\Fitlers\ExtraLarge
.
Inside the applyFilter()
method you can call any methods on the $image
property according to the documentation.
<?php
namespace App\Filters;
use Intervention\Image\Image;
use Intervention\Image\Filters\FilterInterface;
class ExtraLarge implements FilterInterface
{
public function applyFilter(Image $image)
{
return $image->fit(1300, 1000);
}
}
Then inside the route
helper set the value of template to x-large
{{ route('imagecache', ['template' => 'x-large', 'filename' => 'image.jpg']) }}
Upvotes: 4