diff --git a/Imagine/Filter/Loader/UpscaleFilterLoader.php b/Imagine/Filter/Loader/UpscaleFilterLoader.php new file mode 100644 index 000000000..27730145a --- /dev/null +++ b/Imagine/Filter/Loader/UpscaleFilterLoader.php @@ -0,0 +1,46 @@ + + */ +class UpscaleFilterLoader implements LoaderInterface +{ + /** + * {@inheritDoc} + */ + public function load(ImageInterface $image, array $options = array()) + { + if (!isset($options['min'])) { + throw new InvalidArgumentException('Missing min option.'); + } + + list($width, $height) = $options['min']; + + $size = $image->getSize(); + $origWidth = $size->getWidth(); + $origHeight = $size->getHeight(); + + if ($origWidth < $width || $origHeight < $height) { + + $widthRatio = $width / $origWidth ; + $heightRatio = $height / $origHeight; + + $ratio = $widthRatio > $heightRatio ? $widthRatio : $heightRatio; + + $filter = new Resize(new Box($origWidth * $ratio, $origHeight * $ratio)); + + return $filter->apply($image); + } + + return $image; + } +} diff --git a/Resources/config/imagine.xml b/Resources/config/imagine.xml index 07f36cdf3..02edbb8c2 100644 --- a/Resources/config/imagine.xml +++ b/Resources/config/imagine.xml @@ -41,6 +41,7 @@ Liip\ImagineBundle\Imagine\Filter\Loader\WatermarkFilterLoader Liip\ImagineBundle\Imagine\Filter\Loader\StripFilterLoader Liip\ImagineBundle\Imagine\Filter\Loader\BackgroundFilterLoader + Liip\ImagineBundle\Imagine\Filter\Loader\UpscaleFilterLoader @@ -160,6 +161,10 @@ + + + + diff --git a/Resources/doc/filters.md b/Resources/doc/filters.md index ebc3d10de..e0e81e58c 100644 --- a/Resources/doc/filters.md +++ b/Resources/doc/filters.md @@ -55,6 +55,19 @@ liip_imagine: relative_resize: { scale: 2.5 } # Transforms 50x40 to 125x100 ``` +### The `upscale` filter + +The upscale filter, as the name implies, performs a upscale transformation +on your image. Configuration looks like this: + +``` yaml +liip_imagine: + filter_sets: + my_thumb: + filters: + upscale: { min: [800, 600] } +``` + ### The `crop` filter The crop filter, as the name implies, performs a crop transformation