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) ? '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/@frsource/is-animated"></script>
In Node.js
import { readFileSync } from 'fs';
import isAnimated from '@frsource/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.`);