In this article we will be comparing algorithms to compress webp image. To do this, we will be using our Java image library, JDeli. We will be comparing file size, quality of output, and speed.
For the baseline of our comparisons, we will use the following uncompressed image. It has a file size of 180KB. It takes just under 3 seconds to encode.
What types of compression does WebP support?
Unlike most other image formats, WebP has both a lossless and lossy compression format. Which is best for you all depends…
What is Lossy webp compression?
When you compress webp images with lossy compression, it also is known as the irreversible compression due to the fact some data is removed. The process uses the VP8 prediction code commonly used for videos which includes the algorithm DCT (Discrete cosine transform) to then be able to remove redundant data. This does mean webp quality loss is expected but usually not visible, also something to bear in mind you cannot return to the original quality once you have applied this compression. The advantage is that this compression can reduce webp size much more effectively.
Using lossy compression reduced the file size to 6KB and took just under 2 seconds, and the quality was set to a default of 75.
What is Lossless webp compression?
This compression unlike lossy, preservers the original data so when decoded can return the file to its original form. To achieve this, multiple transformations are made including several color transforms along with a spatial transform and then finished off by applying a form of entropy coding known as LZ77 huffman coding. This does then mean that the reduction in file size won’t be as significant but that is not always the most important aspect when compressing.
Using lossless compression reduced the file size to 67KB and also took just under 2 seconds.
Conclusion
Using our webp compression tool, we can see the lossy far out ranks the lossless compression due to the much smaller file size for similar quality. If you want to reduce webp size, lossy would be your first choice but if you want to be able to return to the original image than the hit of an extra 61KB wouldn’t matter as much especially when they both take the around the same time to complete.
You can learn more about similar image formats by having a look at our Glossary.
Are you a Java Developer working with Image files?
// Read an image
BufferedImage bufferedImage = JDeli.read(dicomImageFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(heicImageFile);
// Write an image
JDeli.write(bufferedImage, "heic", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpegImageFile);
// Write an image
JDeli.write(bufferedImage, "jpeg", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpeg2000ImageFile);
// Write an image
JDeli.write(bufferedImage, "jpx", outputStreamOrFile);
// Write an image
JDeli.write(bufferedImage, "pdf", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(pngImageFile);
// Write an image
JDeli.write(bufferedImage, "png", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(tiffImageFile);
// Write an image
JDeli.write(bufferedImage, "tiff", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(webpImageFile);
// Write an image
JDeli.write(bufferedImage, "webp", outputStreamOrFile);
Why do developers choose JDeli over free alternatives?
- Works with newer image formats such as AVIF, HEIC, JPEG XL, WEBP
- Better support than alternatives for JPEG, PNG, TIFF.
- Prevent JVM crashes caused by native code in other image libraries
- Better performance than other popular Java image libraries