# ts-gif

> TypeScript implementation of a performant GIF encoder & decoder.

Latest version **0.1.2** (published 2025-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-gif
pnpm add ts-gif
yarn add ts-gif
bun add ts-gif
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2025-02-11 |
| First published | 2025-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 41.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Chris Breuer <chris@stacksjs.org> |
| Maintainers | chrisbreuer |
| Keywords | gif, gif89a, gif87a, encoder, decoder, typescript, ts-gif, library |

## Links

- npm: https://www.npmjs.com/package/ts-gif
- Repository: https://github.com/stacksjs/ts-gif
- Homepage: https://github.com/stacksjs/ts-gif#readme
- Issues: https://github.com/stacksjs/ts-gif/issues
- npm.io page: https://npm.io/package/ts-gif

## Dependencies (1)

- [data-uri-to-buffer](https://npm.io/package/data-uri-to-buffer.md) ^6.0.2

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2025-02-11

## README

<p align="center"><img src=".github/art/cover.jpg" alt="Social Card of this repo"></p>

[![npm version][npm-version-src]][npm-version-href]
[![GitHub Actions][github-actions-src]][github-actions-href]
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
<!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
<!-- [![Codecov][codecov-src]][codecov-href] -->

# ts-gif

> A TypeScript library for reading, writing, and manipulating GIF images

## Features

- 🎨 **Complete GIF Support**: Full support for GIF87a and GIF89a specifications
- 🖼️ **Frame Management**: Create and manipulate multi-frame animated GIFs
- 🎯 **Precise Control**: Fine-grained control over frame delays, disposal methods, and transparency
- 🌈 **Color Tables**: Support for both global and local color palettes
- 🔄 **Animation**: Full control over animation loops and timing
- 💪 **Typed**: Written in TypeScript with full type safety
- ⚡ **Efficient**: Optimized for performance with minimal memory footprint
- 🧰 **Simple API**: Easy-to-use interface for both basic and advanced GIF operations

## Get Started

### Installation

```bash
npm install ts-gif
# bun i ts-gif
```

### Usage

```ts
import { Reader, Writer } from 'ts-gif'

// Reading a GIF
const reader = new Reader(buffer)
console.log(`Dimensions: ${reader.width}x${reader.height}`)
console.log(`Number of frames: ${reader.numFrames()}`)

// Writing a GIF
const writer = new Writer(buffer, width, height, {
  palette: globalPalette,
  loop: 0 // 0 = loop forever
})

// Add frames
writer.addFrame(0, 0, width, height, pixelData, {
  delay: 100, // 100ms delay
  disposal: 2, // Clear frame before next
  transparent: null
})

// Finalize the GIF
writer.end()
```

## Testing

```bash
bun test
```

## Changelog

Please see our [releases](https://github.com/stackjs/ts-gif/releases) page for more information on what has changed recently.

## Contributing

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

## Community

For help, discussion about best practices, or any other conversation that would benefit from being searchable:

[Discussions on GitHub](https://github.com/stacksjs/ts-starter/discussions)

For casual chit-chat with others using this package:

[Join the Stacks Discord Server](https://discord.gg/stacksjs)

## Postcardware

Stacks OSS will always stay open-sourced, and we will always love to receive postcards from wherever Stacks is used! _And we also publish them on our website._

Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎

## Credits

Thanks to [Dean McNamee](https://github.com/deanm) for the original [`omggif`](https://github.com/deanm/omggif) library.

## Sponsors

We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.

- [JetBrains](https://www.jetbrains.com/)
- [The Solana Foundation](https://solana.com/)

## License

The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.

Made with 💙

<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/ts-gif?style=flat-square
[npm-version-href]: https://npmjs.com/package/ts-gif
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/ts-starter/ci.yml?style=flat-square&branch=main
[github-actions-href]: https://github.com/stacksjs/ts-starter/actions?query=workflow%3Aci

<!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/ts-starter/main?style=flat-square
[codecov-href]: https://codecov.io/gh/stacksjs/ts-starter -->

---
_Source: https://npm.io/package/ts-gif · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
