The WebP image format is a new image encoding format that’s especially appealing to web developers.
It can encode a high density of information within a given file size, allowing higher quality images at lower file sizes. Considering that images make up about 60-percent of the web, lower image file sizes mean faster loading pages, which is something everyone wants. Let’s talk about what makes WebP special, why it’s worth using, and how you can start using it today.
What is WebP? How Does WebP Work?
WebP’s compression algorithm is based on the intra-frame encoding algorithm used in the VP8 video compression algorithm. As with VP8, it is a block-based transformation scheme with eight bits of color depth and a YUV 1:2 chroma subsampling ratio (YCbCr 4:2:0), which is the same as the default chroma subsampling ratio on MPEG2 and MP4.
For lossy encoding, WebP uses predictive encoding. Essentially, the encoder can try and predict the value of the next block. When the prediction is good, redundant data can then be removed, improving compression. Only a small remainder, called residual, remains to be transmitted in a compressed format.
You can dig into the technical compression methodology on Google’s WebP Compression Techniques page.
What Makes WebP Worth Using?
Most importantly, WebP is able to achieve space savings over JPG, the current image standard. Below, you can see a comparison between WebP and JPG on the same image. There is little apparent loss in visual quality. WebP routinely achieves compression improvements of thirty to fifty percent, making it dramatically more efficient than the now twenty-six year old JPEG standard.
There’s more to WebP than just file size savings, however. The standard also includes far more features that JPEG. Whereas JPEG can compression images by a given percentage, that’s the only affordance made to controlling the compression. WebP, on the other hand, offers the following options:
- Lossless compression
- Lossy compression with percentage scale, similar to JPEG
- Transparency/Alpha Layers
- Transparency/Alpha Layer Compression
- Animated images, similar to GIF
As a result, WebP can end up being a replacement for JPEG, PNG, and GIF file types. However, as we’ve mentioned previously, WebM is the format of choice for modern video and animation playback on the web.
Under lossless WebP, an alpha layer can be added for a file size increase of about 22-percent. Under lossy WebP, lossy alpha layers can be added, achieving file sizes as small as 33-percent of an equivalent PNG file with transparency. As of now, Only WebP supports an 8-bit alpha layer alongside lossy RGB images.
Browser Support for WebP
At the time of publican, WebP is natively supported by as much as 71-percent on global web users, as tracked by CanIUse.com. WebP support was added in Firefox 65 and Edge 18, both of which are the most recent version of each browser at the moment. Support for WebP has existed on Chrome and Opera since 2014. In terms of mobile browsers, Android’s default browser and Google Chrome support WebP.
See a detailed breakdown of browser support here.
The biggest current setback is the format’s support by Apple. As of publication, WebP is not yet natively supported by iOS Safari or macOS Safari. This requires a separate image type to be served for unsupported browsers, bringing us in to the realm of polyfills.
Saving and Opening WebP Images
You’ll need to expand your normal image workflow to add on support for WebP. As of now, Photoshop doesn’t natively support WebP, but that can easily be added.
Firefox and Google Chrome both open WebP files natively, but Preview is currently unable to handle the images, despite being registered as a program capable of opening the file type.
- To open and save WebP in Photoshop on macOS or Windows, download and install the appropriate WebP plugin file for Photoshop.
- macOS users can also download WebP Viewer from the Mac App Store to get a lightweight viewer application for WebP files with bundled Quick Look support.
- Windows users can add decoding support for WebP to Photo Viewer with Google’s WebP Codec, which is compatible with Windows XP SP3 and onwards.
- Linux and macOS users can get command line utilities for encoding and decoding WebP file formats with libwebp, available on Homebrew and direct download.
These files can be loaded into your DOM just like any other image file. In browsers that don’t support WebP natively, Webp Polyfill can load a fallback image file to support less capable browsers.
You might also like the following posts about web standards and image compression:
How to Compress Video For Online Streaming
Implement Autoplaying GIFs Without Using GIFs
How to Reduce Image File Size for Your Website: Best Image Compression Tools
The post The Developer’s Guide to the WebP Image Format appeared first on SpyreStudios.