Amy Pearson Amy is the product lead for JDeli with expertise in image code, Java, web development, and cloud computing. She focuses on JDeli and has also contributed to JPedal, cloud services, and support. Outside work, she enjoys gaming, F1, and music.

How to write WebP images in Java (Tutorial)

2 min read

WEBP icon


how to write webp image (webp icon)

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:

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?

JDeliwebp-imageio
Pure Java (no native binaries)✗ (wraps libwebp)
Works as ImageIO plugin
Direct API (non-ImageIO)
Lossless + lossy controlLimited
Supports other formats (AVIF, HEIC, TIFF…)
Known CVEsNoneDepends on libwebp version
CostCommercialFree
SupportIncludedGitHub 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:

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.

  1. Add JDeli to your class or module path (trial jar download).
  2. Create a File or OutputStream for the output.
  3. Call JDeli.write() with your image, format, and output target.

Controlling output quality with WebpEncoderOptions

For production use you’ll usually want explicit control over compression. Pass a WebpEncoderOptions object instead:

Key WebpEncoderOptions settings:

MethodValuesEffect
setCompressionFormat(WebpCompressionFormat.LOSSLESS);LOSSLESS or LOSSYLossless preserves every pixel; lossy gives smaller files
setQuality(int)0–100Only 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

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?

Amy Pearson Amy is the product lead for JDeli with expertise in image code, Java, web development, and cloud computing. She focuses on JDeli and has also contributed to JPedal, cloud services, and support. Outside work, she enjoys gaming, F1, and music.