Link
Skip to main content

Java WebP Writer

Java’s built-in ImageIO does not support writing WEBP files. JDeli is a 100% Java WEBP writer that provides full encoding control with no dependencies.

Getting started

Add JDeli to your project via Maven or Gradle, or see using JDeli with Java modules.

What is supported

The JDeli WEBP writer supports the following features:

Feature Supported
Animation No
Alpha transparency Yes
Compression - Lossy Yes
Compression - Lossless Yes
Metadata EXIF
Output to file Yes
Output to OutputStream Yes
Output to byte[] Yes
Pure Java implementation Yes

Quick start or to replace in existing code using ImageIO:

The simplest way to write a WEBP image is:

JDeli.write(bufferedImage, "webp", file);

Or to a byte array:

byte[] webpData = JDeli.write(bufferedImage, "webp");

Or to an OutputStream:

JDeli.write(bufferedImage, "webp", os);

Simple usage

For better type safety, use OutputFormat:

JDeli.write(myBufferedImage, OutputFormat.WEBP, outputStreamOrFile);

OutputFormat allows setting of any supported Image Format

Benefits:

  • Compile-time safety
  • Cleaner code
  • Recommended for new applications

Advanced usage: controlling the output

Use webpEncoderOptions when you need control over encoding behaviour.

final WebpEncoderOptions options = new WebpEncoderOptions();

//set any options in options instance - examples below
options.setCompressionFormat(WebpCompressionFormat.LOSSLESS);

//write out
JDeli.write(myBufferedImage, options, outputStreamOrFile);

WebpEncoderOptions allows setting of specific options.

Various image processing operations can be conducted on the image, detailed documentation can be found here.

Performance comparisons:

These figures were generated using jmh (as documented on our blog) with a standard set of images (also documented). They should be easy to replicate if you wish to validate, the code is on GitHub.

The higher the number, the better.
Benchmark results using JMH:
Mode: Throughput Count: 25 Units: ops/s

Benchmark Score Error
ImageIO/darkxanter_lossy 6.374 ± 0.233
ImageIO/darkxanter_lossless 1.141 ± 0.029
JDeli_lossy 3.640 ± 0.021
JDeli_lossless 4.477 ± 0.110

Number of files: 166

Benchmark Size unreadable output AVG SSIM score AVG Similarity
ImageIO/darkxanter_lossy 0.568KB 28 0.976483 Very similar (high quality)
ImageIO/darkxanter_lossless 8.860KB 28 0.982474 Very similar (high quality)
JDeli lossy 0.534KB 0 0.953926 Very similar (high quality)
JDeli lossless 9.076KB 2 0.968417 Very similar (high quality)

Tested on 2021 14inch M1 MacBook Pro using JDK 17.0.3


Frequently asked questions

Can Java write or encode WEBP files without external libraries?

No. Java’s built-in ImageIO does not support writing or encoding WEBP files. JDeli provides a pure-Java WEBP encoder with no dependencies required.

Does writing or encoding WEBP in Java with JDeli require additional libraries?

No. JDeli is a 100% Java library with no dependencies. It runs on any platform where the JVM runs with no additional installation.

What output types does JDeli support for writing WEBP?

JDeli can write and encode WEBP to a File, OutputStream, or return the encoded data as a byte array.

See also


Why JDeli?

  • Support image formats such as AVIF, HEIC and JPEG XL that are not supported in Java.
  • Process images up to 3x faster than ImageIO and alternative Java image libraries.
  • Prevent JVM crashes caused by native code in other image libraries such as ImageIO.
  • Handle JPEG, PNG, TIFF image file formats fully in Java.
  • Keep your Image files secure as JDeli makes no calls to any external system or third party library.

Learn more about JDeli

Start Your Free Trial