TL;DR:
Java’s ImageIO does not support WebP by default. To write WebP images in Java you have two options: drop in a plugin so your existing ImageIO code works unchanged, or use JDeli’s API directly. Both are covered below.
Does Java support WebP natively?
No. ImageIO ships without a WebP codec, so both reads and writes fail silently or throw an exception:
// Both of these fail with vanilla ImageIO
// Read
BufferedImage image = ImageIO.read(new File("input.webp")); // returns null
// Write
ImageIO.write(bufferedImage, "webp", new File("output.webp")); // returns false
You need an external library. The two main options are webp-imageio (free, open source) and JDeli (commercial).
JDeli vs webp-imageio: which should you use?
| JDeli | webp-imageio | |
|---|---|---|
| Pure Java (no native binaries) | ✓ | ✗ (wraps libwebp) |
| Works as ImageIO plugin | ✓ | ✓ |
| Direct API (non-ImageIO) | ✓ | ✗ |
| Lossless + lossy control | ✓ | Limited |
| Supports other formats (AVIF, HEIC, TIFF…) | ✓ | ✗ |
| Known CVEs | None | Depends on libwebp version |
| Cost | Commercial | Free |
| Support | Included | GitHub Issues board |
| Actively developed | ✓ | ✗ |
webp-imageio is a reasonable choice for a simple, low-stakes use case. If you’re running a server, distributing an application, or need format breadth beyond WebP, JDeli is the safer option.
Option 1: Add WebP support to ImageIO (no code changes)
JDeli registers itself as an ImageIO plugin, so your existing read/write calls work without modification once it’s on the classpath.
Maven
com.idrsolutions
jdeli
LATEST
Gradle
implementation ‘com.idrsolutions:jdeli:LATEST’
Alternatively, download the trial jar and add it to your classpath manually. Full setup instructions are in the ImageIO configuration docs.
Once JDeli is on the classpath, your existing ImageIO code works unchanged:
// Read — works once JDeli is on the classpath
BufferedImage bufferedImage = ImageIO.read(new File("input.webp"));
// Write — same
ImageIO.write(bufferedImage, "webp", new File("output.webp"));
Option 2: Write WebP directly with the JDeli API
The JDeli API gives you more control and doesn’t depend on ImageIO’s plugin registration order.
- Add JDeli to your class or module path (trial jar download).
- Create a
FileorOutputStreamfor the output. - Call
JDeli.write()with your image, format, and output target.
// String format
JDeli.write(bufferedImage, "webp", new File("/path/to/output.webp"));
// Type-safe enum (preferred)
JDeli.write(bufferedImage, OutputFormat.WEBP, new File("/path/to/output.webp"));
Controlling output quality with WebpEncoderOptions
For production use you’ll usually want explicit control over compression. Pass a WebpEncoderOptions object instead:
WebpEncoderOptions options = new WebpEncoderOptions();
options.setCompressionFormat(WebpCompressionFormat.LOSSLESS); // lossless or lossy
options.setQuality(85); // 0–100, higher = better quality, larger file
JDeli.write(bufferedImage, options, new File("/path/to/output.webp"));
Key WebpEncoderOptions settings:
| Method | Values | Effect |
|---|---|---|
setCompressionFormat(WebpCompressionFormat.LOSSLESS); | LOSSLESS or LOSSY | Lossless preserves every pixel; lossy gives smaller files |
setQuality(int) | 0–100 | Only applies to lossy. 80–90 is a typical production range |
Frequently asked questions
What is the WebP format?
WebP is an image format developed by Google offering both lossy and lossless compression. It typically produces files 25–35% smaller than JPEG at equivalent visual quality, making it a common choice for web performance optimisation.
Which browsers support WebP?
WebP has near-universal browser support — above 97% of global users as of 2024, covering Chrome, Safari, Firefox, Edge and most mobile browsers. See caniuse.com/webp for current data.
Can I read WebP files in Java with JDeli?
Yes. See our companion article: how to read WebP files in Java.
Does JDeli support lossless WebP?
Yes. Set setCompressionFormat(WebpCompressionFormat.LOSSLESS); on a WebpEncoderOptions object before passing it to JDeli.write().
Other useful WebP resources
- How to read WebP files in Java
- How to convert WebP to JPG in bulk
- What is the WebP image format?
- JDeli WebP support documentation
As experienced Java developers, we help you work with images in Java and bring over a decade of hands-on experience with many image file formats.
Are you a Java Developer working with Image files?
// Read an image
BufferedImage bufferedImage = JDeli.read(avifImageFile);
// Write an image
JDeli.write(bufferedImage, "avif", outputStreamOrFile);// 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);
What is JDeli?
JDeli is a commercial Java Image library that is used to read, write, convert, manipulate and process many different image formats.
Why use JDeli?
To handle many well known formats such as JPEG, PNG, TIFF as well as newer formats like AVIF, HEIC and JPEG XL in java with no calls to any external system or third party library.
What licenses are available?
We have 3 licenses available:
Server for on premises and cloud servers, Distribution for use in a named end user applications, and Custom for more demanding requirements.
How does JDeli compare?
We work hard to make sure JDeli performance is better than or similar to other java image libraries. Check out our benchmarks to see just how well JDeli performs.
