Search code examples
wordpresswebptimber

Timber Twig WebP compression level when converting images


I started using the towebp filter to convert images into webp format - very excited about that feature by the way :) While the images looked quite fine in several implementations I just compared the original output of an uploaded image to the converted one and the webp version has much less sharpness. In this case the image is skaled up a little bit but it the same for the original version..

So my question is: can we adjust the webp-quality (compression level) when using the |towebp filter?

And if so - how?

Edit: I just tried to call the filter and passing a numer like:

data-srcset="{{ image_item.src|resize(imgWidthDesktop)|towebp(100) }}"

in hope targeting the quality level. The new generated file has a bigger filesize so I guess it works like that. Still the original image is a little bit more crisp but has double the filesize even when setting 100% webp quality level.

If this is the way to config webp quality level it should be mentioned in the image cookbook: https://timber.github.io/docs/guides/cookbook-images/

Can someone confirm that this is the way to go?


Solution

  • Yes, if we look at source code we can see a $quality argument.

    See

    The default quality is 80