Installation
npm install @frsource/is-animated
yarn add @frsource/is-animated
pnpm add @frsource/is-animated
Demo
Try uploading the image (gif / png / webp) using input below:
Usage
In browser
<input type="file" accept="image/*" />
import isAnimated from '@frsource/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) ? 'Yes' : 'No';
alert(`Is "${this.files[0].name}" animated? ${answer}.`);
});
In Node.js
import { readFileSync } from 'fs';
import isAnimated from '@frsource/is-animated';
const buffer = readFileSync('my-test-file.png');
const answer = isAnimated(buffer) ? 'Yes' : 'No';
console.log(`Is "my-test-file.png" animated? ${answer}.`);