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

Already on GitHub? Sign in to your account

add support to Imagine Basic filters #59

wants to merge 3 commits into


None yet
3 participants

This PR aims to give support to almost all the Imagine basic filters, not only thumbnail.

The list of the new filters supported is:


As described in the documentation, these are the basic filters that could be interesting for image manipulation in twig. Filters like copy or paste are not implemented.

A user would be now able to use all these options in config.yml:

            type:    crop
            options: { start: [0, 0], size: [120, 120] }
            type:    resize
            options: { size: [120, 120] }
            type:    rotate
            options: { angle: 145, background: '#CCC' }
            type:    flipHorizontally
            type:    flipVertically
            type:    thumbnail
            options: { size: [120, 120], mode: outset }
            type:    thumbnail
            options: { size: [120, 120], mode: inset }

@stof stof and 1 other commented on an outdated diff May 6, 2012

if (!isset($options['options'])) {
throw new InvalidArgumentException(sprintf(
'Options for filter type "%s" must be specified', $filter
+ */

stof May 6, 2012


you should remove old code instead of commenting it. Versionning is handled by git, not by comments


inmarelibero May 6, 2012

you're right, I forgot them. fixed


avalanche123 commented May 6, 2012

This is a great idea, thanks for the work. The way you changed filter manager won't allow for extension with custom filter loaders as it will always use the basic filter loader. The idea was to make it easy for users to write loaders for their own filters. I would prefer you left filter manager as is but split the code into individual filter loaders for each filter or registered basic filter loader in DIC for each filter it can load using appropriate tag.

to allow extension with custom filter loaders one solution could be this:

$basicFilters = array('crop', 'resize', 'rotate', 'filpHorizontally', 'flipVertically', 'thumbnail');

if (in_array($options['type'], $basicFilters) {
    return $this->loaders['basicfilters']->load($options);
} else {
    return $this->loaders[$options['type']]->load($options['options']);

would be sufficient?

Yes I considered making one individual filter loaders, but then I saw the amount of code was not big, and also it's intuitive for me that all basic filters would stay in some BasicFilter.php class.
I made a comment on a file, it could resolve custom filter loaders


avalanche123 commented May 6, 2012

I think we should treat all filters the same and configure them using dependency injection container and tags. By hard-coding a special case for basic filters we're not doing mixing configuration with code and not taking advantage of DIC. You should be able to just tag basic filter loader with:

<tag name="imagine.filter.loader" filter="thumbnail" />
<tag name="imagine.filter.loader" filter="crop" />
<tag name="imagine.filter.loader" filter="resize" />
<tag name="imagine.filter.loader" filter="rotate" />
<tag name="imagine.filter.loader" filter="flipHorizontally" />
<tag name="imagine.filter.loader" filter="flipVertically" />

and leave FilterManager untouched

@stof, is this correct?


stof commented May 6, 2012

@avalanche123 yes, except that your compiler pass only reads the first tag and ignore others currently. But it can be fixed easily


avalanche123 commented May 6, 2012

@inmarelibero I merged @stof's pull request, so now you should be able to register one filter loader to load multiple filters like I showed in my comment above. Please update your pull request so I can merge it


avalanche123 commented Nov 3, 2012

this has been stale for a while, are you still interested in landing this in bundle?


avalanche123 commented Nov 5, 2012

closing for the lack of activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment