This short guide explains how to convert GIF to WEBP in Java. It has details to set the IDE for application development, a list of steps, and a sample code for demonstrating a GIF to WEBP converter in Java. Details of all the API features used in the sample code will also be discussed.
Steps to Convert Animated GIF to WEBP in Java
- Set the IDE to use Aspose.Imaging for Java to transform a GIF file to the WEBP format
- Import the desired namespaces Image and WebPOptions to perform the conversion
- Load the source GIF image into the Image class
- Create an instance of the WebPOptions class to customize the output WEBP class
- Call the setLossless() method with a True value to generate the output image without lossy compression
- Save the resultant image as WEBP on the disk
Follow these instructions to transform GIF to WEBP in Java. Add reference to all the namespaces required for the application, instantiate the license to avail full features of the product, load the source GIF file into the image class, and create an instance of the WebPOptions class. Use the WebPOptions object to customize the output WEBP image by setting its parameters, such as compression preferences, and save the resultant image on the disk.
Code for GIF to WEBP Converter Software in Java
The above code demonstrates how to change GIF to animated WEBP in Java, where the source GIF is also an animation; however same code can be used for normal GIF to WEBP conversion. The WebPOptions class can be used for setting the output quality, animation settings, maintaining the metadata, and adjusting the palette and resolution, etc. The image class can detect the loaded image format, resize, rotate, flip, crop, and transform the loaded image before the conversion.
This article has guided us to change a GIF file to the WEBP format. To create a new WEBP file, refer to the article on Create WEBP in Java.