Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How to write WebP images in Java (Tutorial)

0 sec read

WEBP icon

how to write webp image (webp icon)

Why do WEBP Images cause problems for Java Developers?

ImageIO does not support WEBP images by default so existing Java Applications will not work with them. This is an increasing problem as WEBP images are quickly becoming a popular format. It is a well-supported format in browsers and offers significant advantages over established formats such as JPG.

In this post, I will show you how to add WEBP support to existing Java Applications which use ImageIO (without having to make any code changes) and how to write out images as WEBP files in JDeli directly.

What options are there for supporting WEBP files in Java?

Java does not support WEBP images by default so you will need to use an external library or plugin. JDeli gives gives full WEBP support for reading and writing and can also be used an ImageIO plugin.

There is a free, open source plugin called webp-imageio which adds WEBP support to ImageIO.

We recommend JDeli because it is a pure, complete Java implementation with no known security issues. It can be used with existing ImageIO code and has an API to write new code so we will document that in this article. It can also read WebP files and supports several other Image formats.

How to upgrade ImageIO to support WEBP

It’s actually very simple and can be done without changing your existing code!

For example, the code below does not work with ImageIO for WEBP images


Steps to fix:

How to write a WebP images directly with JDeli

  1. Add JDeli to your class or module path. (download link to the trial jar).
  2. Create a File (or OutputStream) object
  3. Pass image, WEBP type, and File (or OutputStream) object into write method

and the Java code to write WebP with JDeli…

In below picture, my original file was a .jpg image, and I used JDeli to write it out as a .webp image.

More on WebP

What are WebP files used for?

The WebP file format was developed by Google to provide high-quality lossy and lossless compression for web images. In this article, I will walk you through how to write out images as WebP images in Java.

Which web browsers support WebP?

WebP is supported by the most popular web browsers including Google chrome, Safari, Microsoft edge, Mozilla firefox and many more.

Other useful WEBP links

How can JDeli help?

JDeli is the best enterprise-level Java image library for image manipulation. You can use JDeli to read, write and convert your images as it has WebP support. Visit our documentation to learn more about JDeli’s WebP support.



Are you a Java Developer working with Image files?

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.