What is WebP and How Does it Work

Author

Reads 722

Close-up of Computer Screen
Credit: pexels.com, Close-up of Computer Screen

WebP is a versatile image format that's been gaining popularity in recent years. It was created by Google in 2010 as a way to compress images while maintaining their quality.

WebP files can be used to store both lossy and lossless compressed images. This means that images can be compressed to a smaller file size while still retaining their original quality.

WebP files are typically smaller in size compared to traditional image formats like JPEG and PNG. This makes them ideal for web use, where faster page loading times are crucial.

By using WebP, developers can reduce the file size of their images and improve the overall user experience.

Intriguing read: Why Do Webp Files Exist

WebP Converter

The WebP Converter is a powerful tool that allows you to convert your favorite images from PNG and JPEG to WebP. You can download the precompiled cwebp conversion tool for Linux, Windows, or macOS.

To convert images to WebP, you can use the cwebp command-line tool or the Imagemin WebP plugin. The Imagemin WebP plugin is a good choice if your project uses build scripts or build tools, while the CLI is better for small projects or one-time conversions.

Credit: youtube.com, The Ultimate WebP Image Converter & Database Cleaner!

You can also use your platform's shell to simplify the conversion process. For example, to convert all JPEG files in a folder on Windows, you can use the following command:

Windows: `cwebp -q 80 *.jpg`

You can specify a quality level from 0 (worst) to 100 (best) when converting images to WebP. It's worth experimenting with different quality levels to find the right tradeoff between image quality and file size for your needs.

Here are some common conversions you can perform using the WebP converter:

  • WEBP to PDF
  • WEBP to AVIF
  • WEBP to BMP
  • WEBP to EPS
  • WEBP to GIF
  • WEBP to ICO
  • WEBP to JPG
  • WEBP to ODD
  • WEBP to PNG
  • WEBP to PS
  • WEBP to PSD
  • WEBP to TIFF
  • WEBP to WEBP

WebP Technology

WebP's lossy compression algorithm is based on the intra-frame coding of the VP8 video format and the Resource Interchange File Format (RIFF) as a container format.

The RIFF container has an overhead of only twenty bytes, though it can also hold additional metadata. WebP images have a side length limited to 16383 pixels.

WebP uses a block-based transformation scheme with eight bits of color depth and a luminance–chrominance model with chroma subsampling by a ratio of 1:2 (YCbCr 4:2:0).

Credit: youtube.com, The Most HATED Image Format

Here's a breakdown of the first 20 bytes of a WebP image:

WebP's block prediction is based on values from the three blocks above it and from one block to the left of it, with four basic modes of block prediction: horizontal, vertical, DC, and TrueMotion.

Lossless Compression

WebP's lossless compression uses advanced techniques such as dedicated entropy codes for different color channels.

This allows for more efficient compression, especially when dealing with images that have a lot of color variation. The lossless compression algorithm was designed by Google software engineer Jyrki Alakuijala.

It exploits 2D locality of backward reference distances, which helps to reduce the amount of data needed to represent an image. This complements basic techniques such as dictionary coding, Huffman coding, and color indexing transform.

A color cache of recently used colors is also used to improve compression efficiency. This recursive definition means that all control images, including local entropy code selection, are encoded the same way as the whole image itself.

Additional reading: Is Webp Lossless

Animation

Credit: youtube.com, How To Convert GIF To Animated WebP | WWW.TOOLSBOX.COM

Google has proposed using WebP for animated images as an alternative to the popular GIF format. This is due to the advantages of 24-bit color with transparency.

WebP offers the ability to combine frames with lossy and lossless compression in the same animation, and support for seeking to specific frames. This is a significant improvement over GIF.

Google reports a 64% reduction in file size for images converted from animated GIFs to lossy WebP. However, this comes with a very noticeable visual impact.

When converting using lossless WebP, a 19% reduction is achieved as reported by Google. In real-world performance, the reduction is nearer to 10%.

If you're considering switching to WebP for your animated images, keep in mind that the trade-off between file size and visual quality may be worth it for some applications.

Display Mode Support

WebP does not offer progressive or interlaced display like JPEG or PNG, which can be taxing on the CPU and memory.

Credit: youtube.com, Google I/O 2013 - WebP: Deploying Faster, Smaller, and More Beautiful Images

Decoding a progressive JPEG image is equivalent to decoding the baseline one three times, which can be resource-intensive.

WebP's incremental decoding feature is a more efficient alternative, allowing it to produce a displayable sample row as soon as possible using all available incoming bytes of the bitstream.

This incremental decoding saves memory, CPU, and re-paint effort on the client while providing visual cues about the download status.

The incremental decoding feature is available through the Advanced Decoding API, making it a valuable tool for developers.

WebP Benefits

WebP images are significantly smaller in size compared to traditional image formats like JPEG and PNG, with a typical reduction of 30% in file size. This makes them ideal for web developers looking to reduce page load times and improve user experience.

By compressing images using WebP, you can save bandwidth and reduce the time it takes for images to load on your website. This is especially important for users with slower internet connections or those accessing your site on mobile devices.

WebP also supports lossless compression, which allows for high-quality images to be compressed without sacrificing any of their original quality. This makes it a great option for applications where image quality is paramount, such as in graphic design and photography.

Benefits of Animated

Credit: youtube.com, "Summary of Video Benefits" Animated Commercial

Animated images in WebP files can significantly reduce page load times, with some studies showing a 40% decrease in load times compared to traditional image formats.

This is because animated images can be compressed more efficiently than static images, resulting in smaller file sizes.

WebP's support for animations also enables the creation of interactive and engaging web experiences, such as animations, GIFs, and even short videos.

By using WebP's animation features, developers can create more dynamic and immersive content without compromising on file size or load times.

A fresh viewpoint: Webp File Type

Benefits of WebP

Serving WebP images can be a game-changer for your website's performance. By serving WebP images to newer browsers and a fallback image to older browsers, you can improve page load times and user experience.

If your site only supports WebP compatible browsers, you can stop reading, but for most websites, serving WebP images to the right browsers is a great idea.

Maximum Image Size

Credit: youtube.com, What Is WebP Image Format? - BusinessGuide360.com

WebP images have a unique approach to size limits. The maximum pixel dimensions of a WebP image is 16383 x 16383.

This is due to the 14-bit width and height encoding used by WebP.

How to Judge Image Quality

Judging image quality can be a challenge, especially with new file formats like WebP. You can convert WebP files into PNG to view them in any browser or image viewer.

Converting WebP to PNG allows you to compare image quality side by side. The Gallery on this site features photo comparisons that can give you a quick idea of WebP quality.

WebP files can be deceiving, with some looking better than others, even when they're the same quality. Viewing them alongside their PNG counterparts helps you see the differences.

By converting WebP to PNG, you can get a better sense of how the image will look when viewed in different browsers or image viewers.

WebP Usage

Credit: youtube.com, What image type should you use for the best balance of performance and quality?

You can verify if your website is using WebP by running the Lighthouse Performance Audit. Lighthouse will list any images that are not being served in WebP format.

To do this, run the Lighthouse Performance Audit and look for the results of the Serve images in next-gen formats audit. Lighthouse will highlight any issues with image serving.

If you want to convert your personal images to WebP, you can use the WebP command line utility. This will allow you to convert your images to the WebP format.

If this caught your attention, see: Obsidian Convert to Webp

Server-Side Content Negotiation

Server-side content negotiation can greatly simplify content delivery by allowing web servers to send the most suitable format to clients based on their preferences.

By including an "Accept" request header in the client's request, browsers can indicate which content formats they are willing to accept in response.

This means that if a browser indicates it will "accept" the image/webp format, the web server can safely send WebP images, streamlining content negotiation.

Some CDN providers offer WebP support detection as part of their service, making it easier to serve WebP images only to clients that can display them properly.

WebP Usage

Credit: youtube.com, How to Use webp Images in HTML

WebP is natively supported in many popular web browsers, including Google Chrome, Safari, Firefox, Edge, and Opera.

You can easily create optimized WebP alternatives for your current images and serve them to browsers that support WebP.

WebP includes support for lossy, lossless, and alpha images, as well as animations.

To detect browser support for WebP, you can use client-side or server-side techniques, or take advantage of WebP support detection offered by some CDN providers.

Here are some techniques for detecting WebP support:

  • Client-side detection
  • Server-side detection
  • CDN provider support

To serve WebP images effectively, you should serve them to newer browsers and a fallback image to older browsers.

Lighthouse can be used to verify that all images on your site are being served using WebP.

Using Java Bindings in Android Project

To use libwebp in your Android project, you'll need to set up the ADT plugin and NDK tools. Make sure your NDK path is set correctly in the Preferences > Android > NDK section.

Credit: youtube.com, Android Java Binding Library Project

Create a new project by going to File > New > Project > Android Application Project. Then, clone or unpack libwebp to a folder named jni in the new project.

You'll need to add swig/libwebp_java_wrap.c to the LOCAL_SRC_FILES list. To do this, right-click on the new project and select Android Tools > Add Native Support... to include the library in your build.

To build libwebp as a shared library, go to the project properties and select C/C++ Build > Behaviour. Add ENABLE_SHARED=1 to the Build (Incremental build) section.

Here are the steps to include libwebp in your Android project:

  1. Make sure you have the ADT plugin installed along with NDK tools and your NDK path is set correctly.
  2. Create a new project: File > New > Project > Android Application Project.
  3. Clone or unpack libwebp to a folder named jni in the new project.
  4. Add swig/libwebp_java_wrap.c to the LOCAL_SRC_FILES list.
  5. Add swig/libwebp.jar to the libs/ project folder.
  6. Build your project.
  7. Use System.loadLibrary("webp") to load the library at runtime.

Note that setting NDK_TOOLCHAIN_VERSION=4.8 can improve 32-bit build performance.

WebP Development

Building libwebp as a DLL allows you to import its API functions in C#. This is done by running nmake /f Makefile.vc CFG=release-dynamic.

To use libwebp in C#, you need to add the DLL to your project and import the desired functions. The simple API requires calling WebPFree() to free any buffers returned. You can import functions like WebPEncodeBGRA and WebPFree using the DllImport attribute.

Credit: youtube.com, Convert Images to WebP in WordPress | Bulk Image Optimization to Speed Up WordPress Performance

Here's a basic example of how to use WebPEncodeBGRA:

```markdown

[DllImport("libwebp.dll", CallingConvention = CallingConvention.Cdecl)]

static extern int WebPEncodeBGRA(IntPtr rgba, int width, int height, int stride, float quality_factor, out IntPtr output);

void Encode() {

Bitmap source = new Bitmap("input.png");

BitmapData data = source.LockBits(new Rectangle(0, 0, source.Width, source.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

IntPtr webp_data;

const int size = WebPEncodeBGRA(data.Scan0, source.Width, source.Height, data.Stride, 80, out webp_data);

// ...

WebPFree(webp_data);

}

```

Graphics Software

Graphics software has come a long way in supporting WebP format. By 2011, plugins for several popular graphics software programs were available to support WebP.

Some notable graphics software that added native support for WebP include Pixelmator Classic, which supported WebP from version 1.6.2 released on October 6, 2010. Acorn also added native support for WebP from version 2.6 released on October 21, 2010.

ImageMagick, a popular image processing software, added support for WebP from version 6.6.8-5 released on March 14, 2011. GraphicConverter, another popular graphics software, added support for WebP from version 7.2 released on April 8, 2011.

Broaden your view: Webp Browser Support

Credit: youtube.com, What Are Webp Images And Should You Use Them? - Graphic Design Nerd

Here's a list of some popular graphics software that support WebP:

Modernizr

Modernizr is a JavaScript library that makes it easy to detect HTML5 and CSS3 feature support in web browsers.

It's a game-changer for developers who want to ensure their websites look great and function properly across different browsers.

Modernizr allows you to check for specific features, such as Modernizr.webp, which indicates support for WebP image format.

You can also check for more advanced features like Modernizr.webp.lossless, Modernizr.webp.alpha, and Modernizr.webp.animation, which provide more detailed information about WebP support.

Getting Source Code

Getting Source Code is a straightforward process. The converter code is available on the downloads section of the WebP open-source project page.

If you're interested in the lightweight decoder, you can find the code on the WebM site. The VP8 specification is also located there.

The RIFF Container page provides the container specification.

C# Usage

You can use libwebp with C# by importing the libwebp API functions.

Credit: youtube.com, Using C# for web development

To build libwebp.dll, use the command "nmake /f Makefile.vc CFG=release-dynamic". This will export the API functions.

Add libwebp.dll to your C# project and use the DllImport attribute to import the desired functions. The CallingConvention should be set to CallingConvention.Cdecl.

The WebPEncodeBGRA function can be used to encode an image to WebP format. It takes several parameters, including the image data, width, height, stride, and quality factor.

Here's an example of how to use the WebPEncodeBGRA function:

```csharp

[DllImport("libwebp.dll", CallingConvention = CallingConvention.Cdecl)]

static extern int WebPEncodeBGRA(IntPtr rgba, int width, int height, int stride, float quality_factor, out IntPtr output);

```

Note that if you're using the simple API, you should call WebPFree() to free any buffers returned.

Here's an example of how to use WebPFree():

```csharp

[DllImport("libwebp.dll", CallingConvention = CallingConvention.Cdecl)]

static extern int WebPFree(IntPtr p);

```

Take a look at this: Webp Example

Why Did Google Release It as Open Source?

Google released WebP as open source because they deeply believe in the importance of the open source model. This allows anyone to work with the format and suggest improvements.

With WebP in open source, Google is confident that it will become even more useful as a graphic format over time.

WebP Limitations

Credit: youtube.com, Does WebP Reduce Image Quality? - SearchEnginesHub.com

Converting a PNG image with few colors to lossy WebP can result in a larger file size due to the introduction of new colors that are harder to compress.

In some cases, converting a JPEG source to lossy WebP or a PNG source to lossless WebP can also lead to larger file sizes.

This is not limited to WebP, and can occur when converting to other formats like PNG or JPEG.

Here are some scenarios where file size surprises can happen:

  • Converting a PNG image with few colors to lossy WebP
  • Converting a JPEG source to lossy WebP
  • Converting a PNG source to lossless WebP

It's worth noting that these issues can be mitigated by adjusting the quality settings or using alternative compression methods.

Image Scaling Limitations

Image scaling limitations can be a bit tricky with WebP images. You might be surprised to find that a WebP image can grow larger than its source image in certain situations.

Converting a PNG image with few colors to lossy WebP can introduce new colors that are harder to compress, resulting in a larger file size.

Credit: youtube.com, How Do I Resize A WebP Image? - Graphic Design Nerd

If you're working with a lossy source image, using lossless WebP compression can also lead to a larger file size, regardless of the format you're converting to.

Converting a JPEG file to WebP with a higher quality setting than the original can also result in a larger file size.

You can avoid these file size surprises by lowering the target WebP quality or targeting a specific file size using the -size option in the cwebp tool.

The maximum pixel dimensions of a WebP image is 16383 x 16383, giving you plenty of room to work with even for large images.

Here are some scenarios where file size surprises can occur:

  • Converting a PNG image with few colors to lossy WebP
  • Using lossless WebP compression on a lossy source image
  • Converting a JPEG file to WebP with a higher quality setting than the original

Disadvantages and Criticism

WebP files take significantly more time to create than other web image formats due to the complexity of their compression method.

One of the biggest drawbacks of WebP is its limited color support, specifically only 8-bit YUV 4:2:0 format, which can cause color loss on images with thin contrast elements.

Image on Smartphone Screen
Credit: pexels.com, Image on Smartphone Screen

Fiona Glaser, a developer of the x264 encoder, criticized WebP in 2010, stating that the quality of the WebP-encoded result was the worst of the three tested encodings, mostly due to blurriness on the image.

WebP's optimization for peak signal-to-noise ratio (PSNR) was seen as a major issue by Glaser, who argued that good psycho-visual optimizations are more important than PSNR for compression.

In 2013, Josh Aas from Mozilla Research conducted a comprehensive study and found that WebP did not outperform JPEG by any significant margin.

WebP's lack of support is a significant issue, with Wes Fenlon of PC Gamer describing them as "rampant" and "annoying", commonly rejected for uploading by various content management systems and software programs.

Photoshop didn't officially support WebP until February 2022, highlighting the format's limited adoption.

The fact that WebP images are often downloaded as JPEGs or PNGs, despite not being those file formats, is a major source of frustration for users, making it difficult to use the images after downloading.

Expand your knowledge: What Browesr Does Not save as Webp

WebP Security

Credit: youtube.com, This image Can Hack You (The .webp Exploit)

In September 2023, two critical vulnerabilities relating to WebP images were discovered by Apple Security Engineering and Architecture (SEAR) and the Citizen Lab.

These vulnerabilities, potentially affecting Google Chrome, Chromium-based browsers, and the libwebp project from Google, had a high risk rating of CVSS 8.8.

CVE-2023-4863 was an actively exploited vulnerability that could lead to an out of bounds/overflow condition in applications using the affected libwebp library.

This vulnerability could result in a denial of service (DoS), or worse, enabling malicious remote code execution (RCE).

The extensive use of libwebp packages across hundreds of applications posed a major patching challenge to mitigate the vulnerability.

Several web browsers, including Google Chrome, Firefox, Microsoft Edge, and Brave, issued security patches following the discovery of the vulnerability.

The vulnerability was patched in libwebp version 1.3.2.

Frequently Asked Questions

Why is everyone using WebP now?

WebP offers superior compression efficiency compared to JPEG, resulting in faster download speeds and reduced storage space. This makes it a popular choice for users looking to optimize their image files.

Ellen Brekke

Senior Copy Editor

Ellen Brekke is a skilled and meticulous Copy Editor with a passion for refining written content. With a keen eye for detail and a deep understanding of language, Ellen has honed her skills in crafting clear and concise writing that engages readers. Ellen's expertise spans a wide range of topics, including technology and software, where she has honed her knowledge of Microsoft OneDrive Storage Management and other related subjects.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.