From 07613c2b5f99fdeeb4963e5e8cb35316e7c61c6a Mon Sep 17 00:00:00 2001 From: Maxime Colin Date: Thu, 26 Sep 2013 14:54:29 +0200 Subject: [PATCH 1/3] Add upscale filter --- Imagine/Filter/Loader/UpscaleFilterLoader.php | 46 +++++++++++++++++++ Resources/config/imagine.xml | 5 ++ 2 files changed, 51 insertions(+) create mode 100644 Imagine/Filter/Loader/UpscaleFilterLoader.php diff --git a/Imagine/Filter/Loader/UpscaleFilterLoader.php b/Imagine/Filter/Loader/UpscaleFilterLoader.php new file mode 100644 index 000000000..3f85b3163 --- /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 * $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 @@ + + + + From 3023ed90aab7483dc2322b25996efbfb6498605b Mon Sep 17 00:00:00 2001 From: Maxime Colin Date: Thu, 26 Sep 2013 15:04:31 +0200 Subject: [PATCH 2/3] Fix typo --- Imagine/Filter/Loader/UpscaleFilterLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Imagine/Filter/Loader/UpscaleFilterLoader.php b/Imagine/Filter/Loader/UpscaleFilterLoader.php index 3f85b3163..27730145a 100644 --- a/Imagine/Filter/Loader/UpscaleFilterLoader.php +++ b/Imagine/Filter/Loader/UpscaleFilterLoader.php @@ -36,7 +36,7 @@ public function load(ImageInterface $image, array $options = array()) $ratio = $widthRatio > $heightRatio ? $widthRatio : $heightRatio; - $filter = new Resize(new Box($$origWidth * $origHeight * $ratio)); + $filter = new Resize(new Box($origWidth * $ratio, $origHeight * $ratio)); return $filter->apply($image); } From 117fd3980f0e55ab587c4c49f9cf91ab5d426510 Mon Sep 17 00:00:00 2001 From: Maxime Colin Date: Thu, 26 Sep 2013 15:40:17 +0200 Subject: [PATCH 3/3] Update doc --- Resources/doc/filters.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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