Gregwar/ImageBundle

Optimize images using jpegoptim or other optimizer

Ziiweb opened this issue · 2 comments

Hi,

I'm interested in optimizing my rendered images using a kind of optimizer like jpegoptim.

I have thought in using assetic filters like here:

<img src="{{ jpegoptim('@AcmeFooBundle/Resources/public/images/example.jpg') }}" alt="Example"/>

but that syntax is colliding with ImagineBundle syntax:

<img src="{{ image(...

Well, I say "colliding" because I have tried this:

    <img  src="{{ jpegoptim(" {{ image('images/' ~ producto.imageName).scaleResize(null, 450) }} ") }}" />

and I get this:

An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "_assetic_768aa82" as such route does not exist.")

I have been thinking in creating a custom filter that includes the jpegoptim optimization process, and that could be concatenate to the rest of the filters:

scaleResize(null, 450).MyOptimFilter

Any advice to get image optimization using in the same time ImagineBundle filters?

You can't run assetic filters with dynamic data within, because assetic works before the twig interpreter starts (it's something like preprocessor in C).

What's exactly the interrest of jpegoptim in your case?