/

The WebP Image Format: Generate Smaller and Better-Looking Images

The WebP Image Format: Generate Smaller and Better-Looking Images

Introduction

WebP is an Open Source image format developed by Google that offers the ability to generate smaller images compared to JPG and PNG formats while maintaining high quality. Unlike other formats, WebP supports transparency and animations, making it a versatile option for various types of media. By allowing users to set the quality ratio, WebP provides the flexibility to prioritize either smaller file sizes or better image quality.

Overview:

  • Introduction
  • How much smaller?
  • Generating WebP images
  • Browsers support
  • How can you use WebP today?

How much smaller?

The reduction in image size is a significant advantage of using WebP. Google conducted a comparative study of 1 million images and found that WebP achieves higher compression than both JPEG and JPEG 2000. The greatest gains in file size reduction were observed for smaller images, which are prevalent on the web. However, the actual image size reduction may vary depending on the type of images you plan to use. It is recommended to experiment with different images to determine the best results for your specific requirements.

Generating WebP images

Converting images to WebP format is straightforward. Most modern graphic and image editing tools have built-in export capabilities for WebP files. Additionally, Google provides command-line tools, such as cwebp, which allows for direct conversion of images to WebP. You can find these tools for download on the Google website. Using the cwebp utility, you can convert images by running a command similar to: cwebp image.png -o image.webp. For a comprehensive list of options, you can use cwebp -longhelp.

Browsers support

WebP is currently supported by several browsers, including Chrome, Opera, Opera Mini, UC Browser, and Samsung Internet. However, only Chrome for Desktop and Opera 19+ fully implement all WebP features, including lossy compression, lossless compression, transparency, and animation. Other browsers offer partial support. Notably, Safari and Internet Explorer do not support WebP, and it is unlikely that these browsers will implement support in the near future. Nevertheless, Firefox has supported WebP since version 65 (January 2019), and Edge supports it since version 18. When considering using WebP, it is crucial to evaluate the impact on image size compared to other image optimization methods using JPG/PNG formats.

How can you use WebP today?

There are a few different approaches to implementing WebP on your website. One option is to use a server-level mechanism that automatically serves WebP images instead of JPG and PNG when the HTTP_ACCEPT request header contains image/webp. This method is transparent to both you and your web pages. Another option is to utilize Modernizr and check the Modernizr.webp setting. If you do not need to support Internet Explorer, the <picture> tag is a convenient way to implement WebP. This tag is now supported by all major browsers except Opera Mini and IE. Although primarily used for responsive images, the <picture> tag can also handle WebP images. In a <picture> tag, you can specify a list of images, with the first image being in WebP format and the fallback being a JPG image for browsers that do not support WebP:

1
2
3
4
<picture>
<source type="image/webp" srcset="image.webp">
<img src="image.jpg" alt="An image">
</picture>

Tags: WebP format, image compression, image optimization, image formats, smaller file sizes, better image quality, transparency, animations, Modernizr, responsive images, picture tag