Google’s WebP image format offers better compression rates and features than the other classic formats (JPG, GIF, and PNG) and is already available for use in all major browsers. However, the new AVIF format offers compression rates up to 30% better than WebP and some additional features, with the drawback that, unlike WebP, the AVIF format is not yet available in most browsers and its images require a bit more processing effort to be decod .
Previously we saw how to include WebP images in HTML , but we did not explain how to convert images to WebP , or the features that this format has. In this post we will see everything about WebP and the new AVIF format.
What are WebP and AVIF image formats?
The Web Picture Format ( WebP ) image format is We provide outstanding databases, with zero accuracy compromise and qualitative updates for reaching your target shop audience. Ultimately, we enough your business forward towards perfection to have not error in its database. We also update our database on a weekly basis. High-resolution or volume database weir list websites off data bases of ours licens under an Open Source license and incorporates almost all the functionalities of the other Web image formats and, all other things being equal, offers better compression rates.
The AVIF (AV1 Image File Format) image format is open like Webp, it offers the same features as WebP , better compression at the cost of longer processing time and some additional functionality, which we will talk about later.
Therefore, both formats are suitable for almost any situation , making it easier to decide which format is most suitable for each image , this being one of its main advantages.
History of WebP
It is said that the WebP format was invent by Google, but this is only half true. In fact, Google bought a company call On2 Technologies that had develop a video encoder call VP8 . Google engineers analyz the compression ratios of the algorithms us by VP8 to individually compress each frame and found that they achiev very good compression ratios. Therefore, they decid to use these algorithms to create the WebP image format.
For the VP8 video encoder they creat a container call WebM , one of the video formats with the best compression rates and the greatest support on the web. Like any other container or video file type such as .MP4, .MOV, .AVI or .MKV, WebM can internally use different encoders for video and audio, the most advanc currently being VP9 for video and Opus for audio . In this post we will only analyze the WebP image format.
History of AVIF
The AVIF format was creat by the Alliance for Open Mia (AOMia), a company specializing in the development of video streaming technologies. The invention of AVIF has follow the same path as WebP and, like WebP, is bas on how a video encoder, in this case AV1 , encodes frames . This is why AVIF is the acronym for AV1 Image File Format .
Browser Compatibility
Currently, all browsers support WebP . The only problem is that the desktop version of Safari only supports the format with the Big Sur version or higher of Mac OS. Therefore, until a few years have pass, it will be advisable to continue supporting these older versions of Mac OS in web development. To do this, we can indicate different image formats in the HTML or change the images to the WebP version when the HTTP header parameter “Accept” is detect on the server, with the type “image/webp”, as this website does.
AVIF is currently only support by Google Chrome for desktop and Android, the native Android browser, and Opera . So there are still many browsers that ne to add support for this format. However, it is already recommend to use it because Google Chrome has the largest share of users and therefore, by optimizing for this browser, we obtain a performance benefit that will affect most visits . The MIME type us by this format is “image/avif”, and this format can be specifi along with WebP as follows:
Advantages and features of WebP and AVIF compar to other formats
WebP and AVIF image formats currently support all the features we will see in the following points. These mimic those of other formats that they replace and which we will discuss next to each feature.
Lossy compression without transparency , just like JPG , but with higher compression, using modifications and additional steps of the original JPG algorithm. In WebP, if we increase the compression a lot, we will see that the algorithm divides the image into 16×16 pixel squares. This effect is accentuat in JPEG but with AVIF the squares are not as noticeable. In this case, we will see that the details are blurr as if it were an impressionist painting (see image below). Example of a maximally compress image in JPEG, WebP and AVIF formats.
For the example above, the images have been compress as follows:
JPEG : Using the Gimp program, the quality was lower to 0 and 4:2:0 subsampling was select (roughly, subsampling indicates the resolution us for each channel in YUV color mode). A 3KB image was obtain .
WebP : Using the command line tool cwebp, the parameter -q 0 (indicates minimum quality) was us. Here, subsampling cannot be chosen and in lossy compression it is always 4:2:0. A 2 KB image was obtain .
What is the best way to compress images in WebP or AVIF?
AVIF : Using the command line tool avifenc, the parameters –min 63 –max 63 (indicates minimum quality), -y 420 (subsampling 4:2:0), -s 0 (maximum CPU cost) were us. A 1KB image was obtain.
Obviously, we are never going to compress images to the maximum, but it is a good way to demonstrate that more modern formats allow for lowering the quality further and, therefore, increasing compression without affecting the image.
Lossless compression with transparency , just like PNG, but with a denser and faster compression in the case of Webp and much denser and somewhat slower in the case of AVIF .
In WebP, when lossless compression is us, a different algorithm or format is appli internally that works exclusively with 24-bit color per pixel, in RGB color mode. This means 8 bits for each of the three channels. When there is transparency, we will have 8 more bits for the alpha channel, making a total of 32 bits per pixel.
AVIF , on the other hand, adds quite interesting additional features, although it is rare for browsers to incorporate them. It allows 8, 10 or 12 bits of color depth for each of the channels , with which we will have images with gradients that we can only appreciate on a professional monitor and graphics card for photography. In addition, it allows to have images in HDR , a relatively easier feature to find on a user monitor.
The only classic format that sometimes outperforms
WebP is PNG-8, when we have images with very few colors . PNG-8 is a format in which we use 8 bits per index color pixel, this means that we will have a palette of 256 colors chosen from the more than 16 million available to represent the image. If we cut this palette even further when saving the file, either because the image allows it or by applying a dither to the image, the savings achiev will be greater compar to the WebP version, which always works with at least 24 bits .
AVIF also works with at least 24 bits, but the compression is so good that it beats PNG-8 by a long shot.
Neither WebP nor AVIF are vector image formats, that’s what SVG is for . In these cases, SVG will usually win out over the rest, although since it’s the only one that is sav in text mode, we must keep in mind that it’s also the only image format that should be subject to Brotli q11 or Gzip compression at the server level.
With certain images in WebP, the savings are not excessive compar to the version us in the classic image format. In these cases, the optimization effort requir to have the image in both formats may not be worth it, depending on whether this task has been automat or not. Thus, if we analyze a website with PageSpe Insights or Lighthouse, it will recommend using WebP for an image only if the savings are greater than 8 KB.
It must be said that the APNG standard
Which allows for 24-bit animations with lossless compression in PNGs , wins in compression over animations made with Webp, even when the latter uses lossy compression. APNG is not available in all browsers, but it is in most, so it is an option to consider in these cases.
In addition to all of the above, neither WebP nor AVIF support the progressive or interlac display us by JPEG and PNG respectively. Progressive display consists of displaying the entire image with progressively less pixelation as it is download . According to WebP documentation, this type of display would introduce a very high CPU cost.
The famous image iting program Gimp allows you to open images and export them to WebP. If you don’t know it, I invite you to try this fantastic free and Open Source software. However, with none of the above options are we going to get good results. The best option and the one with which we will get smaller file sizes is the official command line tool cwebp , available at the following link:
There are also programming libraries that allow you to integrate WebP compression into a CMS .
We will choose the most up-to-date version for our operating system, download and unzip the zip , where we will find a /bin folder.
In this example we compress a PNG image with a quality of 80%, blending the transparent parts with white and without saving transparency information. There are many more options: for example, instead of using “–blend_alpha”, we could indicate a transparency quality level of 60% with “–alpha_q 60” or remove the alpha channel with “-noalpha” and it will fill the transparent pixels with colors similar to the ones around them.
Command-line tools may seem cumbersome to users, but happen czech republic telegram data little by they are the ideal interface for developers and system administrators who want to automate the conversion of a large set of images .
Finally, many CDNs offer the possibility of compressing images in WebP or AVIF without having to do anything other than activate the option in their panel.
Conclusion
AVIF is the best web-bas format currently ao lists available , as the increase in CPU usage it produces over WebP is not significant and the compression obtain is much higher . Being a patent-free format, it meets all the requirements to replace the rest, something that will little, which in the long run will save work when creating different versions of the file format for each image . However, it will take a long time before all browsers support it, so we still ne to use AVIF alongside WebP and the classic formats to support all browsers and thus offer users images in the smallest possible size.
To use the compression tool we will write in the terminal:
In the field of photo and image iting applications, even WebP, after several years, still does not have native support in most of them, so the best and most up-to-date option for compressing in the new formats will continue to be the official command line tools for a long time .