is-animated-gif
v1.0.3
Published
Detect animated GIFs from JS Buffer/Stream.
Downloads
16
Maintainers
Readme
is-animated-gif
Detect animated GIFs from JavaScript buffers. Also supported with Typescript.
Motivation
Process the streamed/buffered GIF files to determine whether it is an animated GIF or not. This is a rewritten code based off on another work as a purpose to adapt to TypeScript: https://github.com/mailcharts/animated-gif-detector
Installation
NPM:
npm i is-animated-gif
Yarn:
yarn add is-animated-gif
Usage/Functions
Async (Stream)
This function is intended to be used with Stream:
Function: isAnimatedGifStream()
Params: Stream
(such as: stream.Stream
, stream.Readable
, or http.IncomingMessage
)
Returns: Boolean
Example:
const file = path.resolve(`./test/files/large-size-not-animated.gif`);
const stream = fs.createReadStream(file);
isAnimatedGifStream(stream);
// ...
External Image example:
http.get(
'http://smb3a.weebly.com/uploads/1/0/0/7/1007956/7027030.gif',
async (res) => {
const result = await isAnimatedGifStream(res);
// ...
}
);
Sync (Buffer)
This function is intended to be used with Buffer:
Function: isAnimatedGif()
Params: Buffer
Returns: Boolean
Example:
const file = path.resolve('./path/to/file.gif');
const buffer = fs.readFileSync(file);
isAnimatedGif(buffer);
// ...
Tests
Simply execute npm test
or yarn test
runs the tests.
Please contribute weird animated GIFs to the repository to add to the test cases.
Credits
Special thanks to the MailChart team and other contributers for their hard work!
- Tom Buchok (author) - GitHub/tbuchok
- Bradley Spaulding - GitHub/bspaulding
- Vilson Vieira - GitHub/automata
- Andreas Lind - GitHub/papandreou
- Priyank Parashar - GitHub/paras20xx