animated-gif-detector

1.2.0 • Public • Published

animated-gif-detector

Detect animated GIFs from JavaScript buffers.

Installation

npm i animated-gif-detector

Motivation

Given a readable stream or a buffer directly, determine if a buffer of data is an animated GIF. This helps determine if a document contains cat pics or LOLz.

Usage

Streaming

This module is intended to be used as a Writable stream:

var fs = require('fs')
  , animated = require('animated-gif-detector')
;
fs.createReadStream('file.gif')
  .pipe(animated())
  .on('animated', function() {
    console.log('detected animation!');
  }); 
;

Particularly, you may want to determine animate as early as possible in a given HTTP request, and abort the request as soon as you know:

var http = require('http')
  , animated = require('animated-gif-detector')
;
var req = http.get('http://domain.com/file.gif')
  .pipe(animated())
  .once('animated', function() {
    req.abort();
    // do something else!
  })
;

Sync

If an img is loaded as a buffer directly, a sync function is also available:

var fs = require('fs')
  , animated = require('animated-gif-detector')
;
 
animated(fs.readFileSync('file.gif')) // => true!

Browserify

This should work as a client-side package if Browersified.

Tests

npm test runs the tests.

Please contribute weird animated GIFs to the repository to add to the test cases.

Contributors

Thanks to hard work from the following contributors:

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.04,710latest

Version History

VersionDownloads (Last 7 Days)Published
1.2.04,710
1.1.70
1.1.60
1.1.50
1.1.40
1.1.30
1.1.20
1.1.10
1.1.00
1.0.00
0.3.00
0.2.00
0.1.10
0.1.01
0.0.10

Package Sidebar

Install

npm i animated-gif-detector

Weekly Downloads

4,711

Version

1.2.0

License

ISC

Last publish

Collaborators

  • tbuchok