Represents a GIF image as an array of frames, an Animation whose encode() and decode() work with GIFs. Array methods like map and filter return plain arrays.

Use Animation, which works the same and also handles APNG: new Animation(frames, loopCount), Animation.decode and Animation.encodeGIF. GIF will be removed in 4.0

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

  • get height(): number

    The animation's height

    Returns number

  • get width(): number

    The animation's width

    Returns number

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>>

  • 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