since we have AVIF and WebP support out of the box in Kirby 3.6., I want to give it a try in a current project, combined with picture and srcset. Here is my setup, maybe its useful to some.
In the config.php I have the following code to set the widths for srcset:
I’m just wondering why the file sizes of the created .avif and the .webp are always exactly the same. They both are smaller than the corresponding JPEG, but I’d assume that AVIF should be even smaller than the WebP.
I’m using the default GD Lib as thumb driver.
Any ideas?
So, the initial problem is solved with ImageMagick as thumb driver, the rest is turning into a thread about image quality.
Just one last note:
It seems that AVIF needs less quality (which then results in less file size) to be visually at the comparable quality as WebP. See also this article from Smashing Magazine about this topic.
To get better file size for AVIF we therefore need to set a different quality for both formats. So the final code for the config file looks like:
First, I changed driver to ImageMagick, second, in the afiv settings I added a different quality setting. This way I save around 30% in file size compared to WebP and even more compared to JPEG.
I had the same issue a few weeks ago and I also ended up in lowering the quality for AVIF files. But even with this adjustment I still had a few single AVIF images that were larger than WebP.
So I added a few queries to my image component. I take the smallest (640w in your example) and largest (1920w) srcset for each format and create a thumb with the related options. And then I compare the file sizes of them and only return AVIF sources in my picture element if they are smaller than WebP.
This way I avoid unnecessary markup for files that are too big anyway.
Wow, that sounds really sophisticated!
What I’ve tested so far, the AVIF is always smaller, but it might depend on settings and image content.
Most importantly, they both are smaller than JPEG