Created
July 29, 2023 13:35
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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