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 PasteFilterLoader #118

Merged
merged 4 commits into from
Feb 13, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions Imagine/Filter/Loader/PasteFilterLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Liip\ImagineBundle\Imagine\Filter\Loader;

use Imagine\Image\Point;
use Imagine\Filter\Basic\Paste;
use Imagine\Image\ImageInterface;
use Imagine\Image\ImagineInterface;

class PasteFilterLoader implements LoaderInterface
{
public function __construct(ImagineInterface $imagine, $rootPath)
{
$this->imagine = $imagine;
$this->rootPath = $rootPath;
}

public function load(ImageInterface $image, array $options = array())
{
list($x, $y) = $options['start'];
$destImage = $this->imagine->open($this->rootPath.'/../'.$options['image']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the path altered here with /../?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kernel.root_dir points to app/. I figured it'd be more practical if the image path was relative to the project root directory instead of the kernel root directory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you should pass the correct directory directly.

If one would use another directory (you may have a completely different directory structure in your project) it will be annoying that the directory is changed this way. For example I would like to have that image being generated into a temp directory as I will upload it to Amazon S3 afterwards and delete the temporary file.


$filter = new Paste($destImage, new Point($x, $y));
$image = $filter->apply($image);

return $image;
}
}
7 changes: 7 additions & 0 deletions Resources/config/imagine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<parameter key="liip_imagine.filter.loader.resize.class">Liip\ImagineBundle\Imagine\Filter\Loader\ResizeFilterLoader</parameter>
<parameter key="liip_imagine.filter.loader.thumbnail.class">Liip\ImagineBundle\Imagine\Filter\Loader\ThumbnailFilterLoader</parameter>
<parameter key="liip_imagine.filter.loader.crop.class">Liip\ImagineBundle\Imagine\Filter\Loader\CropFilterLoader</parameter>
<parameter key="liip_imagine.filter.loader.paste.class">Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader</parameter>

<!-- Data loaders' classes -->

Expand Down Expand Up @@ -131,6 +132,12 @@
<tag name="liip_imagine.filter.loader" loader="crop" />
</service>

<service id="liip_imagine.filter.loader.paste" class="%liip_imagine.filter.loader.paste.class%">
<tag name="liip_imagine.filter.loader" loader="paste" />
<argument type="service" id="liip_imagine" />
<argument>%kernel.root_dir%</argument>
</service>

<!-- Data loaders -->

<service id="liip_imagine.data.loader.filesystem" class="%liip_imagine.data.loader.filesystem.class%">
Expand Down