Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Upscale filter #248

Merged
merged 3 commits into from
Sep 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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