Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cropped thumbnail filter
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;
}
}
<img src="{{ asset(photo.url)|apply_filter('gallery_cropped') }}" />
services:
class: ChubProduction\Bundle\SiteBundle\Imagine\CroppedThumbFilterLoader
tags:
- { name: imagine.filter.loader, filter: crop_thumb}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.