Class FrameNormalizer

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

public final class FrameNormalizer extends Object
Utility class for normalizing animation frames to a common canvas size.

When creating animated WebP from images of different sizes, all frames must have identical dimensions. This class provides methods to resize and position frames onto a common canvas with configurable fit strategies.

Author:
MrNanko
  • Method Details

    • normalize

      public static List<BufferedImage> normalize(List<BufferedImage> frames)
      Normalizes a list of frames for animation using default strategy.
      • Target size: min width/height among frames (avoids upscaling)
      • Fit: CONTAIN (preserve aspect, letterbox center)
      • Background: transparent
      Parameters:
      frames - Source frames (must be non-empty)
      Returns:
      New list of TYPE_INT_ARGB frames of identical size
      Throws:
      IllegalArgumentException - if frames is null/empty or contains invalid images
    • normalize

      public static List<BufferedImage> normalize(List<BufferedImage> frames, Integer targetWidth, Integer targetHeight, FitMode fitMode, boolean allowUpscale, Color background)
      Normalizes frames to a common canvas with configurable strategy. Returns new TYPE_INT_ARGB frames with identical dimensions.
      Parameters:
      frames - Source frames (must be non-empty)
      targetWidth - Target canvas width (nullable: use min width across frames)
      targetHeight - Target canvas height (nullable: use min height across frames)
      fitMode - How to fit frames onto canvas (CONTAIN/COVER/STRETCH)
      allowUpscale - Whether to allow upscaling smaller images
      background - Background color to fill (use transparent for alpha)
      Returns:
      List of normalized frames (new BufferedImage instances)