npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gif-stream

v1.1.0

Published

A streaming GIF encoder and decoder

Downloads

24

Readme

gif-stream

A streaming GIF encoder and decoder for Node and the browser

Installation

npm install gif-stream

For the browser, you can build using Browserify.

Decoding Example

This example uses the concat-frames module to collect the output of the GIF decoder into an array of frame objects.

var GIFDecoder = require('gif-stream/decoder');
var concat = require('concat-frames');

// decode a GIF file to RGB pixels
fs.createReadStream('in.gif')
  .pipe(new GIFDecoder)
  .pipe(concat(function(frames) {
    // frames is an array of frame objects
    // each one has a `pixels` property containing
    // the raw RGB pixel data for that frame, as
    // well as the width, height, etc.
  }));

Encoding Example

You can encode a GIF by writing or piping indexed/quantized data to a GIFEncoder stream. If you write data to it manually, you need to first quantize the pixel data to produce a color palette and a buffer of indexed pixels. You can use the neuquant module to do this.

Alternatively, if you have a stream of RGB data already, you can pipe it first to a neuquant stream, and then to a GIF encoder, which will do the hard work of quantizing and writing indexed data for you.

var GIFEncoder = require('gif-stream/encoder');
var neuquant = require('neuquant');

// encode an animated GIF file by writing pixels to it.
// you need to manually quantize the data to produce a palette and indexed pixels.
var q = neuquant.quantize(pixels);

var enc = new GIFEncoder(width, height, { palette: q.palette });
enc.pipe(fs.createWriteStream('out.gif'));

// write indexed data
enc.end(q.indexed);

// or, pipe data from another RGB stream
// boom: streaming image transcoding!
fs.createReadStream('rgb.png')
  .pipe(new PNGDecoder)
  .pipe(new neuquant.Stream)
  .pipe(new GIFEncoder)
  .pipe(fs.createWriteStream('out.gif'));

// maybe you want to preserve the original palette and indexing?
// you can do that too!
fs.createReadStream('rgb.png')
  .pipe(new GIFDecoder({indexed: true}))
  .pipe(new GIFEncoder)
  .pipe(fs.createWriteStream('out.gif'));
// somewhat useless example, but this may be useful for instance
// if you are breaking an animated GIF into multiple static GIFs

License

MIT