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 crop filter implementation #123

Merged
merged 3 commits into from Mar 17, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions Imagine/Filter/Loader/CropFilterLoader.php
@@ -0,0 +1,20 @@
<?php

namespace Avalanche\Bundle\ImagineBundle\Imagine\Filter\Loader;

use Imagine\Image\Box;
use Imagine\Image\Point;

use Imagine\Filter\Basic\Crop;
use Imagine\Image\ImageInterface;

class CropFilterLoader implements LoaderInterface
{
public function load(array $options = array())
{
list($x, $y) = $options['start'];
list($width, $height) = $options['size'];

return new Crop(new Point($x, $y), new Box($width, $height));
}
}
14 changes: 13 additions & 1 deletion README.md
Expand Up @@ -313,6 +313,18 @@ avalanche_imagine:

```

### Crop

The `crop` filter crop an image with start coordinate, and size dimension.

``` yaml
avalanche_imagine:
filters:
crop:
type : crop
options: { start: [0, 0], size: [100, 100] } #crop image with 100x100 square box
```

## Load your Custom Filters

The ImagineBundle allows you to load your own custom filter classes. The only
Expand Down Expand Up @@ -369,4 +381,4 @@ $avalancheService = $this->get('imagine.cache.path.resolver');
Then, call the getBrowserPath and pass the original image webpath and the filter you want to use
```php
$cachedImage = $avalancheService->getBrowserPath($object->getWebPath(), 'my_thumb');
```
```
6 changes: 6 additions & 0 deletions Resources/config/imagine.xml
Expand Up @@ -49,6 +49,8 @@

<parameter key="imagine.filter.loader.chain.class">Avalanche\Bundle\ImagineBundle\Imagine\Filter\Loader\ChainFilterLoader</parameter>

<parameter key="imagine.filter.loader.crop.class">Avalanche\Bundle\ImagineBundle\Imagine\Filter\Loader\CropFilterLoader</parameter>

</parameters>

<services>
Expand Down Expand Up @@ -135,6 +137,10 @@
<argument type="service" id="imagine.filter.manager" />
<tag name="imagine.filter.loader" filter="chain" />
</service>

<service id="imagine.filter.loader.crop" class="%imagine.filter.loader.crop.class%">
<tag name="imagine.filter.loader" filter="crop" />
</service>

</services>
</container>