{"_id":"gifuct-js","_rev":"3810910","name":"gifuct-js","description":"Easy to use efficient .GIF parsing in javascript","dist-tags":{"latest":"2.1.2"},"maintainers":[{"name":"matt-syntropy","email":""}],"time":{"modified":"2025-06-05T11:13:03.000Z","created":"2019-12-29T18:03:36.235Z","2.1.2":"2021-11-04T12:28:51.462Z","2.1.1":"2021-03-19T00:37:51.079Z","2.1.0":"2021-03-18T22:49:57.990Z","2.0.0":"2020-08-27T07:24:11.367Z","1.0.0":"2019-12-29T18:03:36.235Z"},"users":{},"author":{"name":"Matt Way"},"repository":{"type":"git","url":"git+https://github.com/matt-way/gifuct-js.git"},"versions":{"2.1.2":{"name":"gifuct-js","version":"2.1.2","description":"Easy to use efficient .GIF parsing in javascript","main":"lib/index.js","types":"index.d.ts","scripts":{"build":"babel src --out-dir lib","build-demo":"webpack demo/demo.js -o demo/demo.build.js --mode=\"none\""},"repository":{"type":"git","url":"git+https://github.com/matt-way/gifuct-js.git"},"keywords":["gif","parser","javascript"],"author":{"name":"Matt Way"},"license":"MIT","bugs":{"url":"https://github.com/matt-way/gifuct-js/issues"},"homepage":"https://github.com/matt-way/gifuct-js","devDependencies":{"@babel/cli":"^7.10.5","@babel/core":"^7.11.4","@babel/preset-env":"^7.11.0","webpack":"^4.44.1","webpack-cli":"^3.3.12"},"dependencies":{"js-binary-schema-parser":"^2.0.3"},"gitHead":"c497192922d79acc537ec9f4796dfa2d89aaa13a","_id":"gifuct-js@2.1.2","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"shasum":"06152437ba30ec914db8398bd838bd0fbc8a6ecd","size":3726202,"noattachment":false,"key":"/gifuct-js/-/gifuct-js-2.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/gifuct-js/download/gifuct-js-2.1.2.tgz"},"_npmUser":{"name":"matt-syntropy","email":"matt@syntropy.xyz"},"directories":{},"maintainers":[{"name":"matt-syntropy","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gifuct-js_2.1.2_1636028931272_0.6688992367963893"},"_hasShrinkwrap":false,"publish_time":1636028931462,"_cnpm_publish_time":1636028931462,"_cnpmcore_publish_time":"2021-12-16T22:44:17.464Z"},"2.1.1":{"name":"gifuct-js","version":"2.1.1","description":"Easy to use efficient .GIF parsing in javascript","main":"lib/index.js","types":"index.d.ts","scripts":{"build":"babel src --out-dir lib","build-demo":"webpack demo/demo.js -o demo/demo.build.js --mode=\"none\""},"repository":{"type":"git","url":"git+https://github.com/matt-way/gifuct-js.git"},"keywords":["gif","parser","javascript"],"author":{"name":"Matt Way"},"license":"MIT","bugs":{"url":"https://github.com/matt-way/gifuct-js/issues"},"homepage":"https://github.com/matt-way/gifuct-js","devDependencies":{"@babel/cli":"^7.10.5","@babel/core":"^7.11.4","@babel/preset-env":"^7.11.0","webpack":"^4.44.1","webpack-cli":"^3.3.12"},"dependencies":{"js-binary-schema-parser":"^2.0.2"},"gitHead":"462a37340b6171ee65d62e69b7c9e105d337c738","_id":"gifuct-js@2.1.1","_nodeVersion":"12.18.2","_npmVersion":"6.14.5","dist":{"shasum":"ac74ab664bc0726d0a1af3f4fb46f8c0f19d8f43","size":3726330,"noattachment":false,"key":"/gifuct-js/-/gifuct-js-2.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/gifuct-js/download/gifuct-js-2.1.1.tgz"},"_npmUser":{"name":"matt-syntropy","email":"matt@syntropy.xyz"},"directories":{},"maintainers":[{"name":"matt-syntropy","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gifuct-js_2.1.1_1616114270804_0.36930052642473465"},"_hasShrinkwrap":false,"publish_time":1616114271079,"_cnpm_publish_time":1616114271079,"_cnpmcore_publish_time":"2021-12-16T22:44:24.882Z"},"2.1.0":{"name":"gifuct-js","version":"2.1.0","description":"Easy to use efficient .GIF parsing in javascript","main":"lib/index.js","types":"index.d.ts","scripts":{"build":"babel src --out-dir lib","build-demo":"webpack demo/demo.js -o demo/demo.build.js --mode=\"none\""},"repository":{"type":"git","url":"git+https://github.com/matt-way/gifuct-js.git"},"keywords":["gif","parser","javascript"],"author":{"name":"Matt Way"},"license":"MIT","bugs":{"url":"https://github.com/matt-way/gifuct-js/issues"},"homepage":"https://github.com/matt-way/gifuct-js","devDependencies":{"@babel/cli":"^7.10.5","@babel/core":"^7.11.4","@babel/preset-env":"^7.11.0","webpack":"^4.44.1","webpack-cli":"^3.3.12"},"dependencies":{"js-binary-schema-parser":"^2.0.0"},"gitHead":"b24ef4de4b2ec0085cf0882067655bb7acd68584","_id":"gifuct-js@2.1.0","_nodeVersion":"12.18.2","_npmVersion":"6.14.5","dist":{"shasum":"ccc9ae8955c322bb036b01c36488c3282faa8313","size":3726881,"noattachment":false,"key":"/gifuct-js/-/gifuct-js-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/gifuct-js/download/gifuct-js-2.1.0.tgz"},"_npmUser":{"name":"matt-syntropy","email":"matt@syntropy.xyz"},"directories":{},"maintainers":[{"name":"matt-syntropy","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gifuct-js_2.1.0_1616107797636_0.15047872410931595"},"_hasShrinkwrap":false,"publish_time":1616107797990,"_cnpm_publish_time":1616107797990,"_cnpmcore_publish_time":"2021-12-16T22:44:33.224Z"},"2.0.0":{"name":"gifuct-js","version":"2.0.0","description":"Easy to use efficient .GIF parsing in javascript","main":"lib/index.js","scripts":{"build":"babel src --out-dir lib","build-demo":"webpack demo/demo.js -o demo/demo.build.js --mode=\"none\""},"repository":{"type":"git","url":"git+https://github.com/matt-way/gifuct-js.git"},"keywords":["gif","parser","javascript"],"author":{"name":"Matt Way"},"license":"MIT","bugs":{"url":"https://github.com/matt-way/gifuct-js/issues"},"homepage":"https://github.com/matt-way/gifuct-js","devDependencies":{"@babel/cli":"^7.10.5","@babel/core":"^7.11.4","@babel/preset-env":"^7.11.0","webpack":"^4.44.1","webpack-cli":"^3.3.12"},"dependencies":{"js-binary-schema-parser":"^2.0.0"},"gitHead":"bf0d783423c9cde64e83f86581e5442922beefe4","_id":"gifuct-js@2.0.0","_nodeVersion":"12.18.2","_npmVersion":"6.14.5","dist":{"shasum":"e77be31094f6f70dd69a09283ea27e7130e214fa","size":3726395,"noattachment":false,"key":"/gifuct-js/-/gifuct-js-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/gifuct-js/download/gifuct-js-2.0.0.tgz"},"maintainers":[{"name":"matt-syntropy","email":""}],"_npmUser":{"name":"matt-syntropy","email":"matt@syntropy.xyz"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gifuct-js_2.0.0_1598513051113_0.5293770625313483"},"_hasShrinkwrap":false,"publish_time":1598513051367,"_cnpm_publish_time":1598513051367,"_cnpmcore_publish_time":"2021-12-16T22:44:41.427Z"},"1.0.0":{"name":"gifuct-js","version":"1.0.0","description":"Easy to use efficient .GIF parsing in the browser","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/matt-way/gifuct-js.git"},"keywords":["gif","parser","javascript"],"author":{"name":"Matt Way"},"license":"MIT","bugs":{"url":"https://github.com/matt-way/gifuct-js/issues"},"homepage":"https://github.com/matt-way/gifuct-js","devDependencies":{"browserify":"^10.2.6","gulp":"^3.9.0","gulp-jshint":"^1.11.2","gulp-rename":"^1.2.2","gulp-uglify":"^1.2.0","vinyl-buffer":"^1.0.0","vinyl-source-stream":"^1.1.0"},"gitHead":"de68974e9f7fe7ccb52fb1a89cde92c6f8f05af0","_id":"gifuct-js@1.0.0","_nodeVersion":"12.14.0","_npmVersion":"6.13.4","dist":{"shasum":"2893d106b02f6621ec3dd562c00eb4dee55694f4","size":3660008,"noattachment":false,"key":"/gifuct-js/-/gifuct-js-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/gifuct-js/download/gifuct-js-1.0.0.tgz"},"maintainers":[{"name":"matt-syntropy","email":""}],"_npmUser":{"name":"vampirefrog","email":"vampi.npmjs.com@vampi.tech"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gifuct-js_1.0.0_1577642615895_0.5715461566099436"},"_hasShrinkwrap":false,"publish_time":1577642616235,"_cnpm_publish_time":1577642616235,"_cnpmcore_publish_time":"2021-12-16T22:44:48.418Z"}},"readme":"# gifuct-js\r\n\r\nA Simple to use javascript .GIF decoder.\r\n\r\nWe needed to be able to efficiently load and manipulate GIF files for the **[Ruffle][1]** hybrid app (for mobiles). There are a couple of example libraries out there like [jsgif][2] & its derivative [libgif-js][3], however these are admittedly inefficient, and a mess. After pulling our hair out trying to understand the ancient, mystic gif format (hence the project name), we decided to just roll our own. This library also removes any specific drawing code, and simply parses, and decompresses gif files so that you can manipulate and display them however you like. We do include `imageData` patch construction though to get you most of the way there.\r\n\r\n### Demo\r\n\r\nYou can see a demo of this library in action **[here][4]**\r\n\r\n### Usage\r\n\r\n_Installation:_\r\n\r\n    npm install gifuct-js\r\n\r\n_Decoding:_\r\n\r\nThis decoder uses **[js-binary-schema-parser][5]** to parse the gif files (you can examine the schema in the source). This means the gif file must firstly be converted into a `Uint8Array` buffer in order to decode it. Some examples:\r\n\r\n- _fetch_\r\n\r\n        import { parseGIF, decompressFrames } from 'gifuct-js'\r\n\r\n        var promisedGif = fetch(gifURL)\r\n             .then(resp => resp.arrayBuffer())\r\n             .then(buff => parseGIF(buff))\r\n             .then(gif => decompressFrames(gif, true));\r\n\r\n- _XMLHttpRequest_\r\n\r\n        import { parseGIF, decompressFrames } from 'gifuct-js'\r\n\r\n        var oReq = new XMLHttpRequest();\r\n        oReq.open(\"GET\", gifURL, true);\r\n        oReq.responseType = \"arraybuffer\";\r\n\r\n        oReq.onload = function (oEvent) {\r\n            var arrayBuffer = oReq.response; // Note: not oReq.responseText\r\n            if (arrayBuffer) {\r\n                var gif = parseGIF(arrayBuffer);\r\n                var frames = decompressFrames(gif, true);\r\n                // do something with the frame data\r\n            }\r\n        };\r\n\r\n        oReq.send(null);\r\n\r\n_Result:_\r\n\r\nThe result of the `decompressFrames(gif, buildPatch)` function returns an array of all the GIF image frames, and their meta data. Here is a an example frame:\r\n\r\n    {\r\n        // The color table lookup index for each pixel\r\n        pixels: [...],\r\n        // the dimensions of the gif frame (see disposal method)\r\n        dims: {\r\n            top: 0,\r\n            left: 10,\r\n            width: 100,\r\n            height: 50\r\n        },\r\n        // the time in milliseconds that this frame should be shown\r\n        delay: 50,\r\n        // the disposal method (see below)\r\n        disposalType: 1,\r\n        // an array of colors that the pixel data points to\r\n        colorTable: [...],\r\n        // An optional color index that represents transparency (see below)\r\n        transparentIndex: 33,\r\n        // Uint8ClampedArray color converted patch information for drawing\r\n        patch: [...]\r\n     }\r\n\r\n_Automatic Patch Generation:_\r\n\r\nIf the `buildPatch` param of the `dcompressFrames()` function is `true`, the parser will not only return the parsed and decompressed gif frames, but will also create canvas ready `Uint8ClampedArray` arrays of each gif frame image, so that they can easily be drawn using `ctx.putImageData()` for example. This requirement is common, however it was made optional because it makes assumptions about transparency. The [demo][4] makes use of this option.\r\n\r\n_Disposal Method:_\r\n\r\nThe `pixel` data is stored as a list of indexes for each pixel. These each point to a value in the `colorTable` array, which contain the color that each pixel should be drawn. Each frame of the gif may not be the full size, but instead a patch that needs to be drawn over a particular location. The `disposalType` defines how that patch should be drawn over the gif canvas. In most cases, that value will be `1`, indicating that the gif frame should be simply drawn over the existing gif canvas without altering any pixels outside the frames patch dimensions. More can be read about this [here][6].\r\n\r\n_Transparency:_\r\n\r\nIf a `transparentIndex` is defined for a frame, it means that any pixel within the pixel data that matches this index should not be drawn. When drawing the patch using canvas, this means setting the alpha value for this pixel to `0`.\r\n\r\n### Drawing the GIF\r\n\r\nCheck out the **[demo][4]** for an example of how to draw/manipulate a gif using this library. We wanted the library to be drawing agnostic to allow users to do what they wish with the raw gif data, rather than impose a method that has to be altered. On this note however, we provide an easy interface for creating commonly used canvas pixel data for drawing ease.\r\n\r\n### Thanks to\r\n\r\nWe underestimated the convolutedness of the GIF format, so this library couldn't have been made without the help of:\r\n\r\n- [Project: What's In A GIF - Bit by Byte][7] - An amazingly detailed blog by Matthew Flickinger\r\n- [jsgif][2]\r\n- The [*almost correct*] LZW decompression from [this neat gist][8]\r\n\r\n### Who are we?\r\n\r\n[Matt Way][9] & [Nick Drewe][10]\r\n\r\n[Wethrift.com][11]\r\n\r\n[1]: https://www.producthunt.com/posts/ruffle\r\n[2]: http://slbkbs.org/jsgif/\r\n[3]: https://github.com/buzzfeed/libgif-js\r\n[4]: http://matt-way.github.io/gifuct-js/\r\n[5]: https://github.com/matt-way/jsBinarySchemaParser\r\n[6]: http://www.matthewflickinger.com/lab/whatsinagif/animation_and_transparency.asp\r\n[7]: http://www.matthewflickinger.com/lab/whatsinagif/index.html\r\n[8]: https://gist.github.com/devunwired/4479231\r\n[9]: https://twitter.com/_MattWay\r\n[10]: https://twitter.com/nickdrewe\r\n[11]: https://wethrift.com\r\n","_attachments":{},"homepage":"https://github.com/matt-way/gifuct-js","bugs":{"url":"https://github.com/matt-way/gifuct-js/issues"},"license":"MIT"}