Cropped thumbnail filter
services:
class: ChubProduction\Bundle\SiteBundle\Imagine\CroppedThumbFilterLoader
tags:
- { name: imagine.filter.loader, filter: crop_thumb}
<img src="{{ asset(photo.url)|apply_filter('gallery_cropped') }}" />
avalanche_imagine:
filters:
gallery_cropped:
type: crop_thumb
options: { size: [200, 200] }
<?php
namespace ChubProduction\Bundle\SiteBundle\Imagine;
use Imagine\Image\Box;
use Imagine\Image\Point;
use Imagine\Filter\Transformation;
use Avalanche\Bundle\ImagineBundle\Imagine\Filter\Loader\LoaderInterface;
use Imagine\Image\ManipulatorInterface;
/**
* CroppedThumbFilter
*
* @author Vladimir Chub <v@chub.com.ua>
*/
class CroppedThumbFilterLoader implements LoaderInterface
{
public function load(array $options = array())
{
list($width, $height) = $options['size'];
$transformation = new Transformation();
$box = new Box($width, $height);
$transformation->thumbnail($box, ManipulatorInterface::THUMBNAIL_OUTBOUND)
->crop(new Point(0, 0), $box);
return $transformation;
}
}