is-animated

Checks if image is animated 🎞

Installation

npm install is-animated

yarn add is-animated

pnpm add is-animated

Demo

Try uploading the image (gif / png / webp / avif) using input below:

Usage

In Node.js

import { readFileSync } from 'fs';
  import isAnimated from 'is-animated';
  
  const buffer = readFileSync('my-test-file.png');
  const answer = isAnimated(buffer) ? 'IS' : 'IS NOT';
  console.log(`File "my-test-file.png" ${answer} animated.`);

In browser

<input type="file" accept="image/*" />
import isAnimated from 'is-animated';
            
  const input = document.querySelector('input[type="file"]');

  input.addEventListener('change', async function () {
    const arrayBuffer = await this.files[0].arrayBuffer();
    const answer = isAnimated(arrayBuffer) ? 'IS' : 'IS NOT';
    alert(`File "${this.files[0].name}" ${answer} animated.`);
  });

If you prefer, you can import this library using unpkg:

<script defer src="https://unpkg.com/is-animated"></script>