Bethan Palmer Bethan is a Java developer and a Java Champion. She has spoken at conferences including JavaOne/Code One, DevFest and NetBeans days. She has a degree in English Literature.

How to read WebP files in Java

51 sec read

WebP file iconIn this article, I will show you how to read WebP files in Java.

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 (can be cloned from here). Due to this lack of support, we decided to create JDeli, which does not make use of ImageIO and allows you to read WebP images out of the box. JDeli can read and write a very wide range of image formats. Here is the full list on Image file conversions supported.

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"));

To read a webp file using JDeli (Javadoc and download):

//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);

You can find more tutorials in our series on handling common image formats in Java, JDeli and other image libraries.

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

Bethan Palmer Bethan is a Java developer and a Java Champion. She has spoken at conferences including JavaOne/Code One, DevFest and NetBeans days. She has a degree in English Literature.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2019. All rights reserved.