Skip to content
David Mongeau-Petitpas edited this page Mar 29, 2015 · 7 revisions

You can create custom filters to group multiple manipulations in a single filter. Filters can be defined in the boot method of a service provider, either in the AppServiceProvider or you can create a new ImageServiceProvider. It is generally a good idea to use custom filters for the different dimensions you have on a website and enable the serve_custom_filters_only option so it will only be possible to use those filters in url. This way you can prevent a user from creating unwanted images by changing the size in the url.

Using an array of options

Image::filter('thumbnail', array(
	'width' => 100,
	'height' => 100,
	'crop' => true,
	'grayscale' => true
));

Or using a closure and manipulating the Imagine object directly

Image::filter('thumbnail',function($image)
{
	$thumbnail = $image->thumbnail(new Imagine\Image\Box(100,100));
	$thumbnail->effects()->grayscale();
	return $thumbnail;
});

This filter can be used by passing his name in the URL

/uploads/photo-image(thumbnail).jpg

Or by using the method to generate an URL

Image::url('/uploads/photo.jpg',array('thumbnail'));

If you enable serve_custom_filters_only option, the following won't work.

/uploads/photo-image(300x300).jpg

Enabling this option, will force you to use custom filters only