Package dev.matrixlab.webp4j.gif
Class GifToWebPConfig
java.lang.Object
dev.matrixlab.webp4j.gif.GifToWebPConfig
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GifToWebPConfigCreates a default configuration optimized for lossless GIF conversion.static GifToWebPConfigcreateLossyConfig(float quality) Creates a default configuration optimized for lossy GIF conversion.intGets the compression method.intgetKmax()Gets the maximum distance between key frames.intgetKmin()Gets the minimum distance between key frames.intGets the loop count for animation.floatGets the quality factor for lossy compression.booleanChecks if mixed compression mode is enabled.booleanChecks if only the first frame should be extracted.booleanChecks if lossy compression is enabled.booleanChecks if size minimization is enabled.setAllowMixed(boolean allowMixed) Sets whether to allow mixed compression mode.setCompressionMethod(int compressionMethod) Sets the compression method.setExtractFirstFrameOnly(boolean extractFirstFrameOnly) Sets whether to extract only the first frame of an animated GIF.setKmax(int kmax) Sets the maximum distance between key frames.setKmin(int kmin) Sets the minimum distance between key frames.setLoopCount(int loopCount) Sets the loop count for animation.setLossless(boolean lossless) Sets whether to use lossless compression.setMinimizeSize(boolean minimizeSize) Sets whether to minimize output size.setQuality(float quality) Sets the quality factor for lossy compression.
-
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
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
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
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
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
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
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
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
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
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
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
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
-