ImageBundle icon indicating copy to clipboard operation
ImageBundle copied to clipboard

Optimize images using jpegoptim or other optimizer

Open Ziiweb opened this issue 11 years ago • 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?

Ziiweb avatar Apr 16 '14 08:04 Ziiweb

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).

ozahorulia avatar Sep 27 '14 15:09 ozahorulia

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

Gregwar avatar Sep 27 '14 17:09 Gregwar