Skip to content

Instantly share code, notes, and snippets.

@shinshin86
Created July 29, 2023 13:35
Show Gist options
  • Save shinshin86/48704e8e20c0fb80a64e4e55d172c1ba to your computer and use it in GitHub Desktop.
Save shinshin86/48704e8e20c0fb80a64e4e55d172c1ba to your computer and use it in GitHub Desktop.
This is a Node.js script to check if it is an animated GIF.
(async() => {
const gifFrames = require('gif-frames');
const fs = require('fs');
const path = require('path');
const gifPath = process.argv[2];
if(!gifPath) {
console.log('Please provide an gif file as an argument');
process.exit(1);
}
const gifAbsPath = path.resolve(gifPath);
if(!fs.existsSync(gifAbsPath)) {
console.log('The provided gif file does not exists');
process.exit(1);
}
gifFrames({ url: gifAbsPath, frames: 'all', outputType: 'png', cumulative: true })
.then(function (frameData) {
if (frameData.length > 1) {
console.log('This GIF is animated.');
} else {
console.log('This GIF is not animated.');
}
})
.catch(function (err) {
console.error('An error occurred: ', err);
});
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment