aaharu / gifken

JavaScript library that can reverse and split animated GIFs
MIT License
25 stars 3 forks source link
animated-gif gif javascript nodejs typescript wasm

gifken

npm version FOSSA Status

How to use

Split an animated GIF image in browser

<script type="module">
  import {reverse, split} from 'gifken'

  const imageUrl = '/01_Koch-Kurve-Sechseck-alt._Def.-2.gif'
  const response = await fetch(imageUrl)
  const buffer = await response.arrayBuffer()

  const results = await split(new Uint8Array(buffer))
  for (const result of results) {
    const img = new Image()
    img.src = URL.createObjectURL(new Blob([result], {type: 'image/gif'}))
    document.body.append(img)
  }
</script>

Reverse an animated GIF image with Node.js

const {readFileSync, writeFileSync} = require('fs')
const gifken = require('gifken')

gifken
  .reverse(readFileSync('./assets/01_Koch-Kurve-Sechseck-alt._Def.-2.gif'))
  .then(result => {
    writeFileSync('reverse.gif', result)
  })

Build

To build gifken, following tools are required

git clone *thisrepo*
cd gifken
npm install
npm run build

Similar Projects

License

MIT

FOSSA Status