Class AnimatedWebPEncoder

java.lang.Object
dev.matrixlab.webp4j.animation.AnimatedWebPEncoder

public final class AnimatedWebPEncoder extends Object
Encoder for creating animated WebP images from BufferedImage frames.

This class provides methods to create animated WebP images directly from Java BufferedImage objects without requiring an intermediate GIF file.

Author:
MrNanko
  • Method Details

    • encode

      public static byte[] encode(List<BufferedImage> frames, int[] delays, GifToWebPConfig config) throws IOException
      Creates an animated WebP from a list of BufferedImage frames.

      Example usage:

      
       List<BufferedImage> frames = Arrays.asList(frame1, frame2, frame3);
       int[] delays = {100, 100, 100};  // milliseconds per frame
       GifToWebPConfig config = GifToWebPConfig.createLosslessConfig();
       byte[] webp = AnimatedWebPEncoder.encode(frames, delays, config);
       
      Parameters:
      frames - List of BufferedImage frames (must not be empty)
      delays - Array of frame delays in milliseconds (must match frame count)
      config - Configuration for encoding (quality, compression, etc.)
      Returns:
      Byte array containing the animated WebP data
      Throws:
      IOException - If encoding fails
      IllegalArgumentException - If frames is empty or delays length doesn't match
    • encode

      public static byte[] encode(List<BufferedImage> frames, int delay, GifToWebPConfig config) throws IOException
      Creates an animated WebP with uniform delay for all frames.

      This is a convenience method when all frames have the same delay.

      Parameters:
      frames - List of BufferedImage frames (must not be empty)
      delay - Delay in milliseconds for each frame
      config - Configuration for encoding (quality, compression, etc.)
      Returns:
      Byte array containing the animated WebP data
      Throws:
      IOException - If encoding fails
      IllegalArgumentException - If frames is empty