Class Animation

An animation: an array of frames that can be decoded from and encoded to GIF, APNG and WebP. Array methods like map and filter return plain arrays.

Hierarchy (View Summary)

Indexable

Constructors

  • Creates a new animation

    Parameters

    • frames: Frame[]

      The frames to create the animation from

    • loopCount: number = -1

      How many times to repeat the animation (-1 = forever, 0 = play once)

    Returns Animation

Properties

loopCount: number

How many times to repeat the animation (-1 = forever, 0 = play once)

Accessors

  • get duration(): number

    The animation's duration (in ms)

    Returns number

Methods

  • Decodes an animated GIF, APNG or WebP into fully composited frames (still images become a single frame)

    Parameters

    • input: BinaryData

      The binary data to decode

    • onlyExtractFirstFrame: boolean = false

      Whether to stop decoding after the first frame

    Returns Promise<Animation>

  • Encodes the animation as APNG (animated PNG, lossless and with full alpha). Viewers without APNG support show the first frame

    Parameters

    • compression: number = 1

      The zlib compression level (0-9), higher is smaller but slower

    Returns Promise<Uint8Array<ArrayBufferLike>>

  • Encodes the animation as GIF

    Parameters

    • quality: number = 95

      1-100, scales the palette size from 8 colors (1) to 256 colors (90 and above)

    Returns Promise<Uint8Array<ArrayBufferLike>>

  • Encodes the animation as lossless animated WebP

    Returns Promise<Uint8Array<ArrayBufferLike>>

  • Resizes the animation to the given dimensions, scaling every frame and its offsets proportionally. Use Image.RESIZE_AUTO as either width or height to automatically preserve the aspect ratio.

    Parameters

    • width: number
    • height: number
    • mode: ResizeMode = Image.RESIZE_BILINEAR

    Returns this

  • Returns a new animation of the same class containing a range of this one's frames (same semantics as Array.prototype.slice)

    Parameters

    • Optionalstart: number
    • Optionalend: number

    Returns this

  • Returns a string representation of an array.

    Returns string