Enum FitMode

java.lang.Object
java.lang.Enum<FitMode>
dev.matrixlab.webp4j.model.FitMode
All Implemented Interfaces:
Serializable, Comparable<FitMode>

public enum FitMode extends Enum<FitMode>
Defines how frames should be fitted onto a target canvas when normalizing frames for animation.

These modes control how source frames of different dimensions are scaled and positioned onto a uniform canvas size, similar to CSS object-fit behavior.

Since:
2026/1/13 19:45
Author:
MrNanko
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Contain mode: Scale the frame to fit entirely within the canvas while preserving aspect ratio.
    Cover mode: Scale the frame to completely fill the canvas while preserving aspect ratio.
    Stretch mode: Stretch the frame to exactly match the canvas dimensions.
  • Method Summary

    Modifier and Type
    Method
    Description
    static FitMode
    Returns the enum constant of this type with the specified name.
    static FitMode[]
    Returns an array containing the constants of this enum type, in the order they are declared.

    Methods inherited from class java.lang.Enum

    clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • CONTAIN

      public static final FitMode CONTAIN
      Contain mode: Scale the frame to fit entirely within the canvas while preserving aspect ratio.

      The entire source frame will be visible on the canvas. If the aspect ratios don't match, letterboxing (black bars or transparent areas) will appear on the sides or top/bottom.

      Behavior:

      • Scales down to fit if source is larger than canvas
      • Does not scale up by default unless allowUpscale is true
      • Centers the frame on the canvas
      • Preserves aspect ratio - no distortion

      Use case: When you want to ensure the entire frame is visible without cropping.

      Similar to CSS: object-fit: contain

    • COVER

      public static final FitMode COVER
      Cover mode: Scale the frame to completely fill the canvas while preserving aspect ratio.

      The canvas will be entirely covered by the frame. If the aspect ratios don't match, parts of the source frame will be cropped off.

      Behavior:

      • Scales to cover the entire canvas
      • May crop parts of the frame that extend beyond the canvas
      • Centers the frame on the canvas
      • Preserves aspect ratio - no distortion

      Use case: When you want to fill the entire canvas without empty space, accepting potential cropping.

      Similar to CSS: object-fit: cover

    • STRETCH

      public static final FitMode STRETCH
      Stretch mode: Stretch the frame to exactly match the canvas dimensions.

      The frame will be stretched or compressed to fill the entire canvas, potentially distorting the aspect ratio.

      Behavior:

      • Stretches to fill canvas width and height exactly
      • If allowUpscale is false, limits to source size and centers
      • Does NOT preserve aspect ratio - may cause distortion
      • No cropping, no letterboxing

      Use case: When exact canvas coverage is more important than aspect ratio preservation.

      Similar to CSS: object-fit: fill

  • Method Details

    • values

      public static FitMode[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static FitMode valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null