Skip to content

Instantly share code, notes, and snippets.

@ChubV
Created November 1, 2012 19:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChubV/3995779 to your computer and use it in GitHub Desktop.
Save ChubV/3995779 to your computer and use it in GitHub Desktop.
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