LiipImagineBundle: WebP support is broken

Given the following code:

<img src="{{ asset('DSC_3644.JPG') | imagine_filter('thumbnail') }}" alt="DSC_3644.JPG" />

When there is no cache, the src value is https://localhost:8000/media/cache/resolve/thumbnail/DSC_3644.JPG which is handled by the ImagineController and redirect to https://localhost:8000/media/cache/thumbnail/DSC_3644.JPG.webp

When the cache is warmed, the src value is https://127.0.0.1:8000/media/cache/thumbnail/DSC_3644.JPG which is not handled by the ImagineController and returns the JPEG version of the image.

I think we should not support WebP this way and consider using proper content negotiation which will require users to use the <picture> HTML element but will allow deterministic behavior and also support other formats such as AVIF (see https://github.com/liip/LiipImagineBundle/issues/1314).

I didn’t tested it, but this WebP implementation may break HTTP Caching.

I propose to revert https://github.com/liip/LiipImagineBundle/pull/1307 and then to follow this plan:

  • Move to GitHub Actions as travis-ci.com does not support webp (see #1318).

  • Ensure that WebP can be used as a supported format by adding tests and strong configuration validation to ensure that when webp format is requested by the end user, the used driver also support it. This would avoid issues about webp format not working.

At this point, it’s possible to do content negotiation through the use of multiple filters_set (one per format).

  • Allow to use configure multiple formats per filter set to avoid filters_set duplications because of the format and add a format option to the imagine_filter twig filter.

At this point, it’s possible to do content negotiation with <picture> and a single filters_set (configured with multiple formats).

  • Allow server-side content-negotiation. IMHO, this should be done at the twig level. to avoid the issue I described above. A service could also be provided to ease integration with other systems (APIs ?).

At this point, it will be possible to do both client-side and server-side content negotiation with no compromise and also being open to add AVIF and any future format.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 17 (15 by maintainers)

Most upvoted comments

I’d like to add that we should be able to configure when WebP is to be used/redirected. I have extremely-well optimized options for thumbnails, where the JPEG is about 23KB and the same WebP is 240KB. And since I can’t tweak WebP the same way, it’ll always be bigger.

But I would still like to use WebP for the larger, non-thumbnail images, where a full-quality JPEG is 190KB and WebP is 90KB.

@fbourigault proper content negotiation is indeed the way to go.

that being said, the feature as is has been released since I didn’t see this ticket in time (my bad).

so what if we basically deprecate #1307 and then rather work on a 3.0 which features content negotiation?

@fbourigault would you be willing to take the lead here? @peter-gribanov what is your point of view here? would you be motivated to collaborate with @fbourigault on the proposal outlined above?

in that case we would merge #1323 and release 2.4.1 with this fix and a deprecation notice.