Convert WebP to JPG, PNG, and PDF in Java

WebP is the image format introduced by Google that provides lossless and lossy compression for images on the web. WebP images are smaller in size as compared to the well known and vastly used image formats like PNG and JPG, hence provides faster web experience.

Free Online WebP to JPG Converter

If you are here just to online convert your WebP files to JPG, PNG, or PDF documents, use the free conversion tool by GroupDocs. However, if you want to achieve the exact thing programmatically, continue reading.

Despite the fact that WebP images give transparency like PNG, animate like GIF, and the most important for any web developer is the smaller size than comparative quality JPG format, it isn’t still universally compatible. This incomplete support and compatibility issue sometimes force developers to convert the WebP image into JPG, PNG or other formats.

Convert WebP image to JPG, PNG or PDF formats.

GroupDocs provides the solution to convert 50+ document and image file formats. As a developer, you can use GroupDocs.Conversion on-premise and cloud APIs to convert WebP images in your Java, .NET, and many other supported programming languages based applications. As a normal user, you can use GroupDocs.Conversion App to get your WebP image files converted.

Convert WebP to JPG in Java

While using GroupDocs.Conversion API, you can get the possible conversion formats of the source document by using the getPossibleConversions() method of Class ConversionHandler. You can either pass the source document as an InputStream or just pass the file extension of the source document to get the possible conversion formats.

Below source code shows how easily you can now convert the WebP image to JPG format. For the conversion of WebP file to some other supported format, you just have to change the output format of the image by setting the appropriate ImageFileType. For instance, to convert WebP to PNG, just change the below ImageFileType from JPG to PNG.

ConversionHandler conversionHandler = new ConversionHandler(Utilities.getConfiguration());
// Create and set Image Saving Options
SaveOptions saveOption = new ImageSaveOptions();
// Convert the WebP image to JPG or PNG format
String fileName = "image.webp";
ConvertedDocument convertedDocumentPath = conversionHandler.convert(fileName, saveOption);
SaveInfo saveInfo = + "." + convertedDocumentPath.getFileType());

Convert WebP to PDF in Java

WebP image can not just only be converted into any other image file format, however, GroupDocs.Conversion API allows conversion into many document file formats. The following example shows how a Java developer can quickly convert WebP image into PDF (Portable Document Format.)

ConversionHandler conversionHandler = new ConversionHandler(Utilities.getConfiguration());
// Create and set PDF Save Options
PdfSaveOptions saveOption = new PdfSaveOptions();
// Convert the source WebP image to PDF document.
String sourceFileName = "image.webp";
ConvertedDocument convertedDocumentPath = conversionHandler.convert(sourceFileName, saveOption);
SaveInfo saveInfo = + "." + convertedDocumentPath.getFileType());

There are many other open-source examples that are publicly available at GitHub Repository. Download the source code and quickly run the examples using the getting started guide. In case of any difficulty, look at the documentation or reach us at any time on the forum.

Have a nice coding day!

See Also