Class JiffEncoder

Constructors

  • Constructs the GIF encoder.

    Parameters

    • width: number

      An integer representing the GIF image's width, between 1 and 65536.

    • height: number

      An integer representing the GIF image's height, between 1 and 65536.

    Returns JiffEncoder

Properties

height: number

The GIF image's height, between 1 and 65536.

width: number

The GIF image's width, between 1 and 65536.

Methods

  • Adds the next GIF frame. The frame is not written immediately, but is actually deferred until the next frame is received so that timing data can be inserted. Calling GifEncoder.finish will flush all frames.

    Parameters

    • imageData: Uint8ClampedArray | Pick<CanvasRenderingContext2D, "getImageData">

      The image data to add into the next frame.

    Returns void

  • Creates a readable stream and pushes it to the encoder's GifEncoder.readableStreams readable streams.

    Returns Readable

    The new readable stream.

    const encoder = new GifEncoder(320, 240);

    // Stream the results as they are available into hello.gif
    encoder.createReadStream().pipe(fs.createWriteStream('hello.gif'));
  • Uses an existing readable stream and pushes it to the encoder's GifEncoder.readableStreams readable streams.

    Type Parameters

    • T extends Readable

    Parameters

    • readable: T

      The readable stream to use.

    Returns T

    The given readable stream.

  • Creates a write stream.

    Parameters

    Returns Duplex

    A Duplex.

    const { GifEncoder } = require('@skyra/gifenc');
    const encoder = new GifEncoder(400, 200);

    pngStreamGenerator() // A user-defined `Readable`.
    .pipe(encoder.createWriteStream({ repeat: -1, delay: 500, quality: 10 }))
    .pipe(fs.createWriteStream('runningKitten.gif'));
  • Adds final trailer to the GIF stream, if you don't call the finish method the GIF stream will not be valid.

    Returns void

  • Sets the delay time between each frame, or changes it for subsequent frames (applies to the next frame added).

    Parameters

    • delay: number

      The delay between frames, in milliseconds. Must be a number between 655360 and 10.

    Returns this

  • Sets the GIF frame disposal code for the last added frame and any subsequent frames.

    Defaults to one of the following values:

    • 0 : If transparent is set
    • 2 : Otherwise

    Parameters

    Returns this

  • Sets frame rate in frames per second.

    Parameters

    • fps: number

      The amount of frames per second, maximum is 100 frames per second.

    Returns this

  • Sets the quality of color quantization (conversion of images to the maximum 256 colors allowed by the GIF specification). Lower values (minimum = 1) produce better colors, but slow processing significantly. 10 is the default, and produces good color mapping at reasonable speeds. Values greater than 20 do not yield significant improvements in speed.

    Parameters

    • quality: number

      A number between 1 and 30.

    Returns this

  • Sets the number of times the set of GIF frames should be played.

    Parameters

    • repeat: number

      The number of times between -1 and 65536 to repeat the GIF, with two special cases:

      • -1 (default): play once
      • 0: repeat indefinitely

    Returns this

    This method has no effect after the first image was added.

  • Sets the transparent color for the last added frame and any subsequent frames. Since all colors are subject to modification in the quantization process, the color in the final palette for each frame closest to the given color becomes the transparent color for that frame. May be set to null to indicate no transparent color.

    Parameters

    • color: null | number

      The color to be set in transparent pixels.

    Returns this