-1

I'm using LiipImagineBundle in my Symfony2 project and everything is working great. I've defined a thumbnail filter:

<img src="{{ 'bundles/app/images/home/warning.jpg'|imagine_filter('thumb_home') }}" alt="Warning" />

And it works perfectly, but some of my images don't need any filter, so I've tried to remove the filter:

<img src="{{ 'bundles/app/images/home/warning.jpg'|imagine_filter('') }}" alt="Warning" />
<img src="{{ 'bundles/app/images/home/warning.jpg'|imagine_filter() }}" alt="Warning" />

**edited to correct the example as malcolm points out

But it doesn't work, so I need to use Assetic for these images:

{% image '@AppBundle/Resources/public/images/example.jpg' %}
  <img src="{{ asset_url }}" alt="Example" />
{% endimage %}

I can't find in the documentation of the bundle any option which allows me to use the Bundle without filters. Is that true? Of course, I can use the LiipImagineBundle way to include images when they need a filter and the Assetic way when they don't, but switching between two different ways of achieving almost the same thing is pretty annoying.

DandyCC
  • 353
  • 1
  • 6
  • 20
  • If you don't include `imagine_filter()` you don't use the bundle, the problem you have it's not related to imagine bundle. – malcolm Aug 06 '16 at 15:04
  • Do you mean `{{ 'bundles/app/images/home/warning.jpg' | imagine_filter() }}`? That doesn't work. `Warning: Missing argument 2 for Liip\ImagineBundle\Templating\ImagineExtension::filter()` – DandyCC Aug 06 '16 at 15:21
  • No, I mean that in yours second example you don't use imagine bundle, that's why the question is not related to that bundle, and bundle works as expected. – malcolm Aug 06 '16 at 17:07
  • Ohh, yes, that's right. It's a stupid example. Anyway, my question is if there is a way to use de bundle without filters, so obviously it _is_ related to the bundle. – DandyCC Aug 06 '16 at 18:04
  • The bundle is for image filters not for assetic functionality. – malcolm Aug 06 '16 at 19:20

1 Answers1

0

Silly answer to your question - create an original size filter then :). Something like this:

class OriginalSizeFilter implements LoaderInterface
{
    public function load(ImageInterface $image, array $options = [])
    {
        $size = $image->getSize();
        $origWidth = $size->getWidth();
        $origHeight = $size->getHeight();

        $filter = new Thumbnail(new Box($origWidth, $origHeight));
        $image = $filter->apply($image);

        return $image;
    }
}

service:

original_size_filter:
    class: ...\OriginalSizeFilter
    tags:
        - { name: liip_imagine.filter.loader, loader: original_size_filter }

config.yml:

filter_sets:
    original:
        filters:
            original_size_filter: ~

Usage:

<img src="{{ 'bundles/app/images/home/warning.jpg'|imagine_filter('original') }}" alt="Warning" />

But, why not use a asset() function if you don't want any filters to be applied?

xurshid29
  • 4,172
  • 1
  • 20
  • 25