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

added background_image filter #319

Merged
merged 1 commit into from
Feb 7, 2014
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
12 changes: 11 additions & 1 deletion Imagine/Filter/Loader/BackgroundFilterLoader.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Liip\ImagineBundle\Imagine\Filter\Loader;

use Imagine\Image\Box;
use Imagine\Image\Color;
use Imagine\Image\ImageInterface;
use Imagine\Image\ImagineInterface;
Expand All @@ -20,7 +21,16 @@ public function load(ImageInterface $image, array $options = array())
{
$background = new Color(isset($options['color']) ? $options['color'] : '#fff');
$topLeft = new Point(0, 0);
$canvas = $this->imagine->create($image->getSize(), $background);
$size = $image->getSize();

if (isset($options['size'])) {
list($width, $height) = $options['size'];

$size = new Box($width, $height);
$topLeft = new Point(($width - $image->getSize()->getWidth()) / 2, ($height - $image->getSize()->getHeight()) / 2);
}

$canvas = $this->imagine->create($size, $background);

return $canvas->paste($image, $topLeft);
}
Expand Down
10 changes: 10 additions & 0 deletions Resources/doc/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ liip_imagine:
background: { color: '#00FFFF' }
```

If you provide a `size` it will create a new image (this size and given color), and apply the original image on top:

``` yaml
liip_imagine:
filter_sets:
my_thumb:
filters:
background: { size: [1026, 684], color: '#fff' }
```

### The `watermark` filter

The watermark filter pastes a second image onto your image while keeping its ratio.
Expand Down