Skip to content

Instantly share code, notes, and snippets.

@shinshin86
Created July 29, 2023 13:35
Show Gist options
  • Select an option

  • Save shinshin86/48704e8e20c0fb80a64e4e55d172c1ba to your computer and use it in GitHub Desktop.

Select an option

Save shinshin86/48704e8e20c0fb80a64e4e55d172c1ba to your computer and use it in GitHub Desktop.

Revisions

  1. shinshin86 created this gist Jul 29, 2023.
    29 changes: 29 additions & 0 deletions is-animated-gif.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    (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);
    });
    })()