Class GifToWebPConfig

java.lang.Object
dev.matrixlab.webp4j.gif.GifToWebPConfig

public class GifToWebPConfig extends Object
Configuration options for GIF to WebP conversion.

This class encapsulates the parameters used when converting GIF images to WebP format. It provides fine-grained control over encoding quality, compression mode, and animation properties.

Based on Google's gif2webp tool options: https://developers.google.com/speed/webp/docs/gif2webp

  • Constructor Details

    • GifToWebPConfig

      public GifToWebPConfig()
  • Method Details

    • getQuality

      public float getQuality()
      Gets the quality factor for lossy compression.
      Returns:
      Quality value between 0 (worst) and 100 (best). Default is 75.
    • setQuality

      public GifToWebPConfig setQuality(float quality)
      Sets the quality factor for lossy compression.
      Parameters:
      quality - Quality value between 0 (worst) and 100 (best)
      Returns:
      This config instance for method chaining
    • isLossless

      public boolean isLossless()
      Checks if lossy compression is enabled.
      Returns:
      true if using lossy compression, false for lossless
    • setLossless

      public GifToWebPConfig setLossless(boolean lossless)
      Sets whether to use lossless compression. When true, lossless compression is used (recommended for GIF). When false, lossy compression is used.
      Parameters:
      lossless - true for lossless compression, false for lossy
      Returns:
      This config instance for method chaining
    • getCompressionMethod

      public int getCompressionMethod()
      Gets the compression method.
      Returns:
      Compression method value between 0 (fastest) and 6 (slowest). Default is 4.
    • setCompressionMethod

      public GifToWebPConfig setCompressionMethod(int compressionMethod)
      Sets the compression method.
      Parameters:
      compressionMethod - Value between 0 (fastest) and 6 (slowest, best quality)
      Returns:
      This config instance for method chaining
    • isExtractFirstFrameOnly

      public boolean isExtractFirstFrameOnly()
      Checks if only the first frame should be extracted.
      Returns:
      true if extracting first frame only, false to process all frames
    • setExtractFirstFrameOnly

      public GifToWebPConfig setExtractFirstFrameOnly(boolean extractFirstFrameOnly)
      Sets whether to extract only the first frame of an animated GIF. When true, the output will be a static WebP image.
      Parameters:
      extractFirstFrameOnly - true to extract first frame only, false to process all frames
      Returns:
      This config instance for method chaining
    • getLoopCount

      public int getLoopCount()
      Gets the loop count for animation.
      Returns:
      Loop count (0=infinite, -1=use GIF's loop count). Default is -1.
    • setLoopCount

      public GifToWebPConfig setLoopCount(int loopCount)
      Sets the loop count for animation.
      Parameters:
      loopCount - Number of loops (0=infinite, -1=use GIF's loop count)
      Returns:
      This config instance for method chaining
    • getKmin

      public int getKmin()
      Gets the minimum distance between key frames.
      Returns:
      Minimum key frame distance. Default is 9.
    • setKmin

      public GifToWebPConfig setKmin(int kmin)
      Sets the minimum distance between key frames.
      Parameters:
      kmin - Minimum distance (recommended: 9 for lossless, 3 for lossy)
      Returns:
      This config instance for method chaining
    • getKmax

      public int getKmax()
      Gets the maximum distance between key frames.
      Returns:
      Maximum key frame distance. Default is 17.
    • setKmax

      public GifToWebPConfig setKmax(int kmax)
      Sets the maximum distance between key frames.
      Parameters:
      kmax - Maximum distance (recommended: 17 for lossless, 5 for lossy)
      Returns:
      This config instance for method chaining
    • isMinimizeSize

      public boolean isMinimizeSize()
      Checks if size minimization is enabled.
      Returns:
      true if minimizing output size
    • setMinimizeSize

      public GifToWebPConfig setMinimizeSize(boolean minimizeSize)
      Sets whether to minimize output size. When true, the encoder will try to produce the smallest possible file, at the cost of slower encoding.
      Parameters:
      minimizeSize - true to minimize output size
      Returns:
      This config instance for method chaining
    • isAllowMixed

      public boolean isAllowMixed()
      Checks if mixed compression mode is enabled.
      Returns:
      true if allowing mixed compression
    • setAllowMixed

      public GifToWebPConfig setAllowMixed(boolean allowMixed)
      Sets whether to allow mixed compression mode. In mixed mode, the encoder automatically chooses lossy or lossless compression for each frame based on heuristics.
      Parameters:
      allowMixed - true to enable mixed mode
      Returns:
      This config instance for method chaining
    • createLosslessConfig

      public static GifToWebPConfig createLosslessConfig()
      Creates a default configuration optimized for lossless GIF conversion. Recommended for preserving GIF quality without any loss.
      Returns:
      A new GifToWebPConfig with lossless settings
    • createLossyConfig

      public static GifToWebPConfig createLossyConfig(float quality)
      Creates a default configuration optimized for lossy GIF conversion. Recommended for reducing file size at the cost of some quality loss.
      Parameters:
      quality - Quality factor (0-100)
      Returns:
      A new GifToWebPConfig with lossy settings