ImageIO and JAI do not have support for reading the WebP file format. In order to do so you need to find a third party library, for example luciad or JDeli. Due to this lack of support, we decided write our own WebP Decoder which is available as part of JDeli.
First an introduction to WebP images…
What is WebP?
WebP images were created by Google to work on web browsers. They are designed to be small and therefore fast to load, using both lossy and lossless compression. You can read more about the WebP image format in our previous article here.
To read a webp image using a third party library such as luciad:
BufferedImage image = ImageIO.read(new File("input.webp"));
//Read Image (can also be OutputStream or byte array) File webpFile = new File("webpImage.webp"); BufferedImage image = JDeli.read(webpFile);
Or you can use the JDeli WebpDecoder directly:
WebpDecoder decoder = new WebpDecoder(); BufferedImage image = decoder.read(webpByteData);
Why use JDeli?
JDeli offers a range of advantages over ImageIO and alternatives, including:
- prevents heap related JVM crashes
- implements unsupported image formats
- reduce output file size
- improve read/write performance
- supports threading
- superior image scaling algorithms
This article is part of our series on reading and writing image files in Java.