{"_id":"@sindresorhus/gifkit","_rev":"1659227","name":"@sindresorhus/gifkit","description":"Encode, decode, and render GIF files","dist-tags":{"latest":"0.1.1"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"time":{"modified":"2026-11-02T19:15:57.000Z","created":"2026-07-08T22:41:05.463Z","0.1.1":"2026-07-14T13:05:25.442Z","0.1.0":"2026-07-08T22:41:05.463Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/gifkit.git"},"versions":{"0.1.1":{"name":"@sindresorhus/gifkit","version":"0.1.1","description":"Encode, decode, and render GIF files","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/gifkit.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=22"},"scripts":{"benchmark":"node benchmark.js","test":"xo && node --test && tsd"},"keywords":["gif","graphics","image","encoder","decoder","render"],"devDependencies":{"jimp":"^1.6.1","tempy":"^3.2.0","tsd":"^0.33.0","xo":"^4.0.0"},"xo":{"rules":{"no-bitwise":"off","max-lines":"off","unicorn/no-break-in-nested-loop":"off","unicorn/no-useless-spread":"off","node-test/no-conditional-assertion":"off"}},"gitHead":"f43c9453982345621dfc831a86b2cc227451b550","types":"./index.d.ts","_id":"@sindresorhus/gifkit@0.1.1","bugs":{"url":"https://github.com/sindresorhus/gifkit/issues"},"homepage":"https://github.com/sindresorhus/gifkit#readme","_nodeVersion":"22.23.1","_npmVersion":"11.18.0","dist":{"integrity":"sha512-JNTRSqqGVm5tjs/VYwEbVUpPIjZkFNPGadso4mLr7dOwxtPJXpNfaj5KMvNk/3CRLvh5w28Ep3PlGzDx2+gr/Q==","shasum":"f8c4161fb8d1c0091bc48f7e3e6981b3a75ef6bb","tarball":"http://registry-npm.ywwl.com/@sindresorhus/gifkit/download/@sindresorhus/gifkit-0.1.1.tgz","fileCount":14,"unpackedSize":127493,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCdPJilJ0tSGhaUiV5mQmDFj7nW6N86f/jRTt823CBBOwIgbwoUrdILZUhgh1dXH1+owoz6+gIo4mew6FI+4ZcxADU="}],"size":24428,"noattachment":false,"key":"/@sindresorhus/gifkit/-/@sindresorhus/gifkit-0.1.1.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/gifkit_0.1.1_1784034325244_0.9532982946488946"},"_hasShrinkwrap":false,"publish_time":1784034325442,"_cnpm_publish_time":1784034325442},"0.1.0":{"name":"@sindresorhus/gifkit","version":"0.1.0","keywords":["gif","graphics","image","encoder","decoder","render"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"@sindresorhus/gifkit@0.1.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/gifkit#readme","bugs":{"url":"https://github.com/sindresorhus/gifkit/issues"},"xo":{"rules":{"max-lines":"off","no-bitwise":"off","unicorn/no-useless-spread":"off","unicorn/no-break-in-nested-loop":"off","node-test/no-conditional-assertion":"off"}},"dist":{"shasum":"f8a4d74a7e99dd29903370edb3f61e248b678a42","tarball":"http://registry-npm.ywwl.com/@sindresorhus/gifkit/download/@sindresorhus/gifkit-0.1.0.tgz","fileCount":14,"integrity":"sha512-kMZZuAgNFnloNBQbhStDUo3w4dAQvy4JSQo74S0Wml1pg4NBgm8h9K3sbLjdfBwqxVDC3kYIOv1mUCoQp0aHCA==","signatures":[{"sig":"MEUCIGt3W+O/br7Uz7nNXCEW1UqnMuG0Nh0iApHBKTmd0bONAiEAg6ab9wF1qvgFxhXQwuYj5HvBRM6gqALfe5chcB7Qdhk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":127256,"size":24371,"noattachment":false,"key":"/@sindresorhus/gifkit/-/@sindresorhus/gifkit-0.1.0.tgz"},"type":"module","types":"./index.d.ts","engines":{"node":">=22"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"0500e86953c7ef6ceb04d4dee471ff037f0e955b","scripts":{"test":"xo && node --test && tsd","benchmark":"node benchmark.js"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/gifkit.git","type":"git"},"_npmVersion":"11.18.0","description":"Encode, decode, and render GIF files","directories":{},"sideEffects":false,"_nodeVersion":"24.18.0","_hasShrinkwrap":false,"devDependencies":{"xo":"^4.0.0","tsd":"^0.33.0","jimp":"^1.6.1","tempy":"^3.2.0"},"_npmOperationalInternal":{"tmp":"tmp/gifkit_0.1.0_1783550465327_0.07220896632615692","host":"s3://npm-registry-packages-npm-production"},"publish_time":1783550465463,"_cnpm_publish_time":1783550465463}},"readme":"# gifkit\n\n> Encode, decode, and render GIF files\n\nThis package is a small JavaScript GIF toolkit. It can decode GIF87a/GIF89a files into structured blocks, encode structured GIF descriptions back to bytes, and render image blocks to RGBA pixels.\n\n## Install\n\n```sh\nnpm install @sindresorhus/gifkit\n```\n\n> [!NOTE]\n> This package works in both Node.js and the browser. It has no dependencies and uses only standard JavaScript and Web APIs.\n\n## Usage\n\n```js\nimport {decodeAnimatedGIF, encodeAnimatedGIF} from '@sindresorhus/gifkit';\n\nconst bytes = encodeAnimatedGIF(frames, {\n\twidth: 640,\n\theight: 480,\n\tfps: 14,\n\tplayCount: 5,\n\tquality: 0.7,\n});\n\nconst animation = decodeAnimatedGIF(bytes);\n\nconsole.log(animation.frames[0].pixels);\nconsole.log(animation.frames[0].delay);\n```\n\n> [!NOTE]\n> If you accept untrusted input in a server context, it's up to you to enforce limits like timeouts and memory usage.\n\n## Common recipes\n\n### Encode RGBA frames to a GIF\n\n```js\nimport {encodeAnimatedGIF} from '@sindresorhus/gifkit';\n\nconst bytes = encodeAnimatedGIF(frames, {\n\twidth: 640,\n\theight: 480,\n\tfps: 14,\n\tplayCount: 5,\n\tquality: 0.7,\n});\n```\n\nGIF stores frame timing in 0.01 second increments, so `fps` and `delay` values are rounded.\n\nFor photos and screenshots, keep the default `quality` or lower it. Use `quality: 1` only when every frame already has at most 256 exact colors.\n\n### Decode a GIF to RGBA frames\n\n```js\nimport {decodeAnimatedGIF} from '@sindresorhus/gifkit';\n\nconst animation = decodeAnimatedGIF(bytes);\n\nconsole.log(animation.width);\nconsole.log(animation.height);\nconsole.log(animation.frames[0].pixels);\nconsole.log(animation.frames[0].delay);\n```\n\n### Decode and encode again\n\n```js\nimport {decodeAnimatedGIF, encodeAnimatedGIF} from '@sindresorhus/gifkit';\n\nconst animation = decodeAnimatedGIF(bytes);\n\nconst options = {\n\twidth: animation.width,\n\theight: animation.height,\n};\n\nif (animation.playCount !== undefined) {\n\toptions.playCount = animation.playCount;\n}\n\nconst newBytes = encodeAnimatedGIF(animation.frames, options);\n```\n\n### Use per-frame delays\n\n```js\nimport {encodeAnimatedGIF} from '@sindresorhus/gifkit';\n\nconst bytes = encodeAnimatedGIF([\n\t{pixels: frame1, delay: 0.1},\n\t{pixels: frame2, delay: 0.2},\n], {\n\twidth: 640,\n\theight: 480,\n\tplayCount: 5,\n\tquality: 0.7,\n});\n```\n\n## API\n\n### `decodeGIF(inputBytes, options?)`\n\nDecodes a `Uint8Array` containing a GIF file and returns a structured GIF object with logical-screen metadata, extension blocks, image blocks, color tables, and decoded indexed pixels.\n\nOptions:\n\n- `strict` - Default: `true`. Reject reserved bits, malformed extension sequencing, and trailing bytes. Use `false` for best-effort decoding.\n\nDecoding enforces internal pixel, block-count, data sub-block-count, and data payload byte limits to avoid resource exhaustion.\n\n### `decodeAnimatedGIF(inputBytes, options?)`\n\nDecodes an animated GIF to rendered full-frame RGBA frames. This is the easiest API when you want image buffers and frame timing instead of GIF internals.\n\n```js\nimport {decodeAnimatedGIF} from '@sindresorhus/gifkit';\n\nconst animation = decodeAnimatedGIF(bytes);\n\nconsole.log(animation.width);\nconsole.log(animation.height);\nconsole.log(animation.playCount);\nconsole.log(animation.frames[0].pixels);\nconsole.log(animation.frames[0].delay);\n```\n\nReturns:\n\n- `width` / `height` - Logical screen size.\n- `playCount` - Total animation plays. `'forever'` means infinite playback. Omitted when no loop extension was present.\n- `frames` - Rendered full-frame RGBA frames.\n- `frames[].pixels` - `Uint8ClampedArray` of flat RGBA bytes: `[red, green, blue, alpha, ...]`.\n- `frames[].delay` - Frame delay in seconds. GIF stores delays in 0.01 second increments.\n\nOptions:\n\n- `background` - Default: `'transparent'`. Use `'gif'` to render the logical-screen background color.\n- `strict` - Default: `true`. Reject malformed decode data and render data like color indexes outside the active color table. Use `false` for best-effort decoding and rendering.\n\n### `encodeAnimatedGIF(frames, options)`\n\nEncodes RGBA frames as an animated GIF. This is the easiest API when you have a list of image buffers and want a normal animation.\n\n```js\nimport {encodeAnimatedGIF} from '@sindresorhus/gifkit';\n\nconst bytes = encodeAnimatedGIF(frames, {\n\twidth: 640,\n\theight: 480,\n\tfps: 14,\n\tplayCount: 5,\n\tquality: 0.7,\n});\n```\n\nOptions:\n\n- `width` / `height` - Required. Frame size.\n- `fps` - Frames per second for uniform timing. Cannot be combined with per-frame `delay`. GIF stores delays in 0.01 second increments, so timing is rounded to the nearest increment.\n- `playCount` - Total animation plays. Finite values must be integers from `1` to `65_536`. Use `'forever'` for infinite playback. Omit it to omit the loop extension. `playCount: 1` also omits the loop extension because that matches default GIF playback.\n- `quality` - Default: `0.8`. `0...1`, where lower values quantize each frame more aggressively to fit GIF’s 256-color palette. Quantization is per-frame and does not dither. For photos and screenshots, keep the default or lower it. Use `1` only when every frame already has at most 256 exact colors.\n\nFrames can be `Uint8Array` or `Uint8ClampedArray` RGBA pixels. Pixels are flat RGBA bytes: `[red, green, blue, alpha, ...]`.\n\nFor per-frame timing, use frame objects with `pixels` and `delay` in seconds. Delays are rounded to GIF’s 0.01 second increments:\n\n```js\nconst bytes = encodeAnimatedGIF([\n\t{pixels: frame1, delay: 0.1},\n\t{pixels: frame2, delay: 0.2},\n], {\n\twidth: 640,\n\theight: 480,\n\tplayCount: 5,\n\tquality: 0.7,\n});\n```\n\n### `encodeGIF(gif)`\n\nEncodes a structured GIF object to a `Uint8Array`. Use `image` blocks when you already have indexed pixels and a palette. Use `rgbaImage` blocks when you have flat RGBA bytes that fit GIF’s 256-color model.\n\nThe `gif` object has this shape:\n\n- `width` / `height` - Required. Logical screen size.\n- `globalColorTable` - Optional. Global palette as flat RGB bytes (`[red, green, blue, ...]`), a `Uint8Array`, or RGB triplets (`[[red, green, blue], ...]`).\n- `backgroundColorIndex` - Optional. Palette index used as the logical-screen background color. Requires `globalColorTable`.\n- `playCount` - Total animation plays. Finite values must be integers from `1` to `65_536`. Use `'forever'` for infinite playback. Omit it to omit the loop extension. `playCount: 1` also omits the loop extension because that matches default GIF playback.\n- `blocks` - Structured GIF blocks in file order.\n\nEncoded GIFs are always written as GIF89a.\n\nBlock types:\n\n- Indexed image block: `{type: 'image', width, height, pixels, colorTable?}`. `pixels` is one palette index per pixel and uses the image `colorTable` or GIF `globalColorTable`. `left` and `top` are optional image offsets and default to `0`. Advanced fields include `isInterlaced`.\n- RGBA image block: `{type: 'rgbaImage', width, height, pixels}`. `pixels` is flat RGBA bytes: `[red, green, blue, alpha, ...]`. gifkit builds a color table from the pixels, so this only works when the image has at most 256 colors and alpha values are fully transparent or fully opaque. `transparentColor` is the RGB palette value stored for transparent pixels.\n- Graphic control metadata for an image block: `graphicControlExtension: {disposalMethod?, delay?, transparentColorIndex?}`. `delay` is in seconds. `transparentColorIndex` is a palette index, or `undefined` for no transparent color. `disposalMethod` is exposed so structured GIF data can be preserved or re-encoded. It controls what happens to the current frame’s pixels before the next frame is drawn: `'unspecified'` leaves the choice to the decoder, `'keep'` keeps the pixels, `'restoreBackground'` clears them to the background, and `'restorePrevious'` restores the previous canvas. Rendered pixels already have this applied, so most users do not need to read or set it.\n- Comment extension: `{type: 'commentExtension', data}`. Strings must be ASCII.\n- Application extension: `{type: 'applicationExtension', identifier, authenticationCode, data?}`. `authenticationCode` accepts a 3-byte string or byte array. Decoded Netscape loop extensions also expose `isNetscapeLoopingExtension` and `playCount`. When encoding an explicit Netscape application extension block, finite `playCount` values must be from `2` to `65_536` because `1` is represented by omitting the loop extension.\n\nEncoding enforces internal pixel, block-count, encode work cost, data payload byte, and total encoded byte limits to avoid resource exhaustion.\n\nExtension payload strings must contain only ASCII characters. Use `Uint8Array` for binary extension data.\n\n### `renderGIFFrameSequence(gif, options?)`\n\nRenders image blocks as an iterable sequence of full logical-screen RGBA frames while applying transparency and disposal methods. Use this for playback or large GIFs where materializing every rendered frame would be wasteful.\n\n```js\nimport {decodeGIF, renderGIFFrameSequence} from '@sindresorhus/gifkit';\n\nconst gif = decodeGIF(bytes, {strict: false});\n\nfor (const frame of renderGIFFrameSequence(gif, {strict: false})) {\n\tconsole.log(frame.pixels);\n\tconsole.log(frame.delay);\n}\n```\n\nOptions:\n\n- `background` - Default: `'gif'`. Use `'transparent'` to render the logical-screen background as transparent.\n- `strict` - Default: `true`. Reject malformed render data like color indexes outside the active color table.\n- `repeat` - Default: `true`. Repeat according to GIF `playCount` metadata. Missing metadata means one pass, a finite number means that many total passes, and `'forever'` means infinite playback. Set to `false` to render exactly one pass.\n- `signal` - Optional abort signal. When aborted, iteration ends.\n\nYields:\n\n- `left` / `top` - Frame source offset in logical-screen pixels.\n- `width` / `height` - Frame source size.\n- `delay` - Frame delay in seconds.\n- `disposalMethod` - Advanced GIF compositing metadata kept so rendered frames can still be related back to the original GIF structure.\n- `pixels` - `Uint8ClampedArray` of rendered full logical-screen RGBA bytes.\n- `index` - Zero-based image-frame index within the current pass.\n- `loopIndex` - Zero-based repetition index for this frame.\n\n### `renderGIFFrames(gif, options?)`\n\nRenders image blocks to full logical-screen RGBA frames while applying transparency and disposal methods. Most users should use `decodeAnimatedGIF()` instead; use this when you need decoded GIF structure and rendered pixels.\n\nOptions:\n\n- `background` - Default: `'gif'`. Use `'transparent'` to render the logical-screen background as transparent.\n- `strict` - Default: `true`. Reject malformed render data like color indexes outside the active color table.\n\nReturns:\n\n- `width` / `height` - Logical screen size.\n- `playCount` - Total animation plays. `'forever'` means infinite playback. Omitted when no loop extension was present.\n- `frames` - Rendered full logical-screen RGBA frames.\n- `frames[].left` / `frames[].top` - Frame source offset in logical-screen pixels.\n- `frames[].width` / `frames[].height` - Frame source size.\n- `frames[].delay` - Frame delay in seconds.\n- `frames[].disposalMethod` - Advanced GIF compositing metadata kept so rendered frames can still be related back to the original GIF structure. `'unspecified'` leaves the choice to the decoder, `'keep'` keeps the pixels, `'restoreBackground'` clears them to the background, and `'restorePrevious'` restores the previous canvas before the next frame is drawn. gifkit already applies this when producing `frames[].pixels`, so use it only if you need to inspect or preserve the original animation metadata.\n- `frames[].pixels` - `Uint8ClampedArray` of rendered full logical-screen RGBA bytes.\n\nRendering enforces internal logical-screen, rendered-output, render block-count, and image-block pixel limits to avoid huge allocations.\n\n### `indexedImage(pixels, options?)`\n\nUse this when you have raw RGBA pixels, for example from a canvas or image decoder, and want the `pixels` and `colorTable` needed for an image block. It only works when the pixels already fit GIF’s palette model.\n\nConverts RGBA pixels to GIF indexed pixels and a power-of-two color table without quantizing or dithering. Each unique opaque RGB color becomes a palette entry. All fully transparent pixels share one palette entry and set `transparentColorIndex`.\n\nThrows if the image exceeds the internal pixel limit, uses more than 256 palette entries, or uses partial alpha. GIF only supports fully transparent or fully opaque pixels.\n\nOptions:\n\n- `transparentColor` - Default: `[0, 0, 0]`. RGB value stored in the palette entry used for transparent pixels.\n\n```js\nimport {indexedImage} from '@sindresorhus/gifkit';\n\nconst image = indexedImage(new Uint8ClampedArray([\n\t255, 0, 0, 255,\n\t0, 0, 0, 0,\n]));\n\nconsole.log(image.pixels);\nconsole.log(image.colorTable);\n```\n\n## Intentionally unsupported GIF spec features\n\ngifkit focuses on GIF features that are useful in modern JavaScript workflows. It intentionally does not expose the GIF user-input flag, pixel aspect ratio byte, color-resolution metadata, color-table sort flags, or Plain Text Extension rendering/encoding. These are legacy display-era features, are rarely present in real GIFs, and are easy to misunderstand. Unknown extensions, including Plain Text Extensions, are preserved as `unknownExtension` blocks.\n","_attachments":{},"homepage":"https://github.com/sindresorhus/gifkit#readme","bugs":{"url":"https://github.com/sindresorhus/gifkit/issues"},"license":"MIT"}