Class Animation

An animation: frames (Animation.frames) that can be decoded from and encoded to GIF, APNG and WebP.

The animation itself is an array of its frames too (animation[0], animation.map(...)), which is deprecated: in 4.0 it won't extend Array anymore, use Animation.frames instead. Array methods like map and filter return plain arrays.

Hierarchy (View Summary)

Indexable

Constructors

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

  • get frames(): Frame[]

    The animation's frames: an array that changes the animation when it's changed (e.g. push(), splice(), or setting an index), and can be replaced as a whole

    Returns Frame[]

  • set frames(frames: Frame[]): void

    Replaces the animation's frames

    Parameters

    Returns void

Methods

  • Encodes the animation as APNG (animated PNG, lossless and with full alpha). Viewers without APNG support show the first frame. Each frame is stored as the area that changed since the frame before, identical frames are merged (unless the optimize option is false): the file shows exactly the same animation, but doesn't necessarily decode to the same frames

    Parameters

    Returns Promise<Uint8Array<ArrayBufferLike>>

  • Encodes the animation as APNG (animated PNG, lossless and with full alpha). Viewers without APNG support show the first frame. Each frame is stored as the area that changed since the frame before, identical frames are merged (unless the optimize option is false): the file shows exactly the same animation, but doesn't necessarily decode to the same frames

    Parameters

    • Optionalcompression: number

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

    Returns Promise<Uint8Array<ArrayBufferLike>>

  • Encodes the animation as GIF. Like all encoders, it stores each frame as the area that changed since the frame before and merges identical frames (unless the optimize option is false), so the file decodes to what the animation shows, but not necessarily to the same frames. Semi-transparent pixels become opaque or transparent after the frames are composited

    Parameters

    Returns Promise<Uint8Array<ArrayBufferLike>>

  • Encodes the animation as GIF. Like all encoders, it stores each frame as the area that changed since the frame before and merges identical frames (unless the optimize option is false), so the file decodes to what the animation shows, but not necessarily to the same frames. Semi-transparent pixels become opaque or transparent after the frames are composited

    Parameters

    • Optionalquality: number

      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. Each frame is stored as the area that changed since the frame before, identical frames are merged (unless the optimize option is false): the file shows exactly the same animation, but doesn't necessarily decode to the same frames

    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

    Returns this

  • 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
    • Optionalmode: ResizeMode

    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

    Use new Animation(animation.frames.slice(start, end), animation.loopCount): in 4.0 animations aren't arrays anymore

  • A short description for debugging, e.g. Animation<64x64x1000ms>

    Returns string