Skip to content

Commit

Permalink
Merge pull request liip#248 from maximecolin/master
Browse files Browse the repository at this point in the history
Add Upscale filter
  • Loading branch information
havvg committed Sep 30, 2013
2 parents 51e2887 + 117fd39 commit e298ebb
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Imagine/Filter/Loader/UpscaleFilterLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Liip\ImagineBundle\Imagine\Filter\Loader;

use Imagine\Filter\Basic\Resize;
use Imagine\Image\ImageInterface;
use Imagine\Image\Box;
use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface;

/**
* Upscale filter
*
* @author Maxime Colin <[email protected]>
*/
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;
}
}
5 changes: 5 additions & 0 deletions Resources/config/imagine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<parameter key="liip_imagine.filter.loader.watermark.class">Liip\ImagineBundle\Imagine\Filter\Loader\WatermarkFilterLoader</parameter>
<parameter key="liip_imagine.filter.loader.strip.class">Liip\ImagineBundle\Imagine\Filter\Loader\StripFilterLoader</parameter>
<parameter key="liip_imagine.filter.loader.background.class">Liip\ImagineBundle\Imagine\Filter\Loader\BackgroundFilterLoader</parameter>
<parameter key="liip_imagine.filter.loader.upscale.class">Liip\ImagineBundle\Imagine\Filter\Loader\UpscaleFilterLoader</parameter>

<!-- Data loaders' classes -->

Expand Down Expand Up @@ -160,6 +161,10 @@
<tag name="liip_imagine.filter.loader" loader="strip" />
</service>

<service id="liip_imagine.filter.loader.upscale" class="%liip_imagine.filter.loader.upscale.class%">
<tag name="liip_imagine.filter.loader" loader="upscale" />
</service>

<!-- Data loaders -->

<service id="liip_imagine.data.loader.filesystem" class="%liip_imagine.data.loader.filesystem.class%">
Expand Down
13 changes: 13 additions & 0 deletions Resources/doc/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e298ebb

Please sign in to comment.