{"id":13419408,"url":"https://github.com/pkrumins/node-gif","last_synced_at":"2025-04-07T07:16:08.623Z","repository":{"id":57250987,"uuid":"795440","full_name":"pkrumins/node-gif","owner":"pkrumins","description":"A node.js C++ module for creating GIF images and animated GIFs from RGB or RGBA buffers.","archived":false,"fork":false,"pushed_at":"2015-07-22T13:13:09.000Z","size":375,"stargazers_count":213,"open_issues_count":12,"forks_count":29,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-10-13T15:51:06.921Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.catonmat.net","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pkrumins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-07-24T18:42:42.000Z","updated_at":"2024-04-08T21:19:52.000Z","dependencies_parsed_at":"2022-08-24T16:52:11.306Z","dependency_job_id":null,"html_url":"https://github.com/pkrumins/node-gif","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkrumins%2Fnode-gif","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkrumins%2Fnode-gif/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkrumins%2Fnode-gif/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkrumins%2Fnode-gif/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkrumins","download_url":"https://codeload.github.com/pkrumins/node-gif/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608154,"owners_count":20965952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:01:15.586Z","updated_at":"2025-04-07T07:16:08.588Z","avatar_url":"https://github.com/pkrumins.png","language":"C++","readme":"This is a node.js module, writen in C++, that uses giflib to produce GIF images\r\nfrom RGB, BGR, RGBA or BGRA buffers.\r\n\r\nThis module exports `Gif`, `DynamicGifStack`, `AnimatedGif` and `AsyncAnimatedGif`\r\nobjects.\r\n\r\n\r\nGif\r\n---\r\n\r\nThe `Gif` object is for creating simple GIF images. Gif's constructor takes\r\ntakes 5 arguments:\r\n\r\n    var gif = new Gif(buffer, width, height, quality, buffer_type);\r\n\r\nThe first argument, `buffer`, is a node.js `Buffer` that is filled with RGB,\r\nBGR, RGBA or BGRA values.\r\nThe second argument is integer width of the image.\r\nThe third argument is integer height of the image.\r\nThe fourth argument is the quality of output image.\r\nThe fifth argument is buffer type, 'rgb', 'bgr', 'rgba' or 'bgra'.\r\n\r\nYou can set the transparent color for the image by using:\r\n\r\n    gif.setTransparencyColor(red, green, blue);\r\n\r\nOnce you have constructed Gif object, call `encode` method to encode and\r\nproduce GIF image. `encode` returns a node.js Buffer.\r\n\r\n    var image = gif.encode();\r\n\r\n\r\n\r\nSee `tests/gif.js` for a concrete example.\r\n\r\n\r\nDynamicGifStack\r\n---------------\r\n\r\nThe `DynamicGifStack` is for creating space efficient stacked GIF images. This  \r\nobject doesn't take any dimension arguments because its width and height is\r\ndynamically computed. To create it, do:\r\n\r\n    var dynamic_gif = new DynamicGifStack(buffer_type);\r\n\r\nThe `buffer_type` again is 'rgb', 'bgr', 'rgba' or 'bgra', depending on what type\r\nof buffers you're gonna push to `dynamic_gif`.\r\n\r\nIt provides several methods - `push`, `encode`, `dimensions`, `setTransparencyColor`.\r\n\r\nThe `push` method pushes the buffer to position `x`, `y` with `width`, `height`.\r\n\r\nThe `encode` method produces the final GIF image.\r\n\r\nThe `dimensions` method is more interesting. It must be called only after\r\n`encode` as its values are calculated upon encoding the image. It returns an\r\nobject with `width`, `height`, `x` and `y` properties. The `width` and\r\n`height` properties show the width and the height of the final image. The `x`\r\nand `y` propreties show the position of the leftmost upper PNG.\r\n\r\nHere is an example that illustrates it. Suppose you wish to join two GIFs\r\ntogether. One with width 100x40 at position (5, 10) and the other with\r\nwidth 20x20 at position (2, 210). First you create the DynamicGifStack object:\r\n\r\n    var dynamic_gif = new DynamicGifStack('rgb');\r\n\r\nNext you push the RGB buffers of the two GIFs to it:\r\n\r\n    dynamic_gif.push(gif1_buf, 5, 10, 100, 40);\r\n    dynamic_gif.push(gif2_buf, 2, 210, 20, 20);\r\n\r\nNow you can call `encode` to produce the final GIF:\r\n\r\n    var image = dynamic_gif.encode();\r\n\r\nNow let's see what the dimensions are,\r\n\r\n    var dims = dynamic_gif.dimensions();\r\n\r\nThe x position `dims.x` is 2 because the 2nd GIF is closer to the left.\r\nThe y position `dims.y` is 10 because the 1st GIF is closer to the top.\r\nThe width `dims.width` is 103 because the first GIF stretches from x=5 to\r\nx=105, but the 2nd GIF starts only at x=2, so the first two pixels are not\r\nnecessary and the width is 105-2=103.\r\nThe height `dims.height` is 220 because the 2nd GIF is located at 210 and\r\nits height is 20, so it stretches to position 230, but the first GIF starts\r\nat 10, so the upper 10 pixels are not necessary and height becomes 230-10=220.\r\n\r\nSee `tests/dynamic-gif-stack.js` for a concrete example.\r\n\r\n\r\nAnimatedGif\r\n-----------\r\n\r\nUse this object to create animated gifs. The whole idea is to use `push` and `endPush`\r\nmethods to separate frames. The `push` method is used for stacking, you can stack many\r\nupdates in the frame. Then when you call `endPush` the data you had pushed will be taken\r\nas a whole and a new frame will be produced.\r\n\r\nOnce you're done call `getGif` to get the final gif (in memory).\r\n\r\nYou can also make AnimatedGif to write the final animated gif to file. Call `setOutputFile`\r\nmethod to set the output file.\r\n\r\nThere are two examples of animated gifs in tests/animated-gif directory. Take a look\r\nif you're interested:\r\n\r\n    * animated-gif.js shows how to produce an animated gif in memory and then write\r\n                      it to a file yourself (this is not recommended as the files can grow\r\n                      pretty big).\r\n    * animated-gif-file-writer.js shows how to produce an animated gif to a file.\r\n\r\n\r\nAsyncAnimatedGif\r\n----------------\r\n\r\nThis object makes the animated gif creating asynchronous. When you push a fragment\r\nto `AsyncAnimatedGif`, it writes the fragment to a file asynchronously, and then\r\nwhen you're done, it takes all these files and merges them, producing an animated gif.\r\n\r\nYou must specify the temporary directory where `AsyncAnimatedGif` will put the files\r\nto. Do it this way:\r\n\r\n    var animated = new AsyncAnimatedGif(width, height);\r\n    animated.setTmpDir('/tmp');\r\n\r\nYou can only write the animated gifs to files with this object. Don't forget to set\r\nthe output file via `setOutputFile`:\r\n\r\n    animated.setOutputFile('animation.gif');\r\n\r\nNow you can `push` fragments to it and separate frames by `endPush`. After you're done\r\nwith frames, call `encode` to produce the final gif.\r\n\r\nThe `encode` method takes a single argument - function that gets called when the final\r\ngif is produced. The function takes two arguments - `status` which will be true or false,\r\nand `error` which will be the error message in case `status` is false, or undefined if\r\nstatus is true:\r\n\r\n    animated.encode(function (status, error) {\r\n        if (status) {\r\n            console.log('animated gif successful');\r\n        }\r\n        else {\r\n            console.log('animated gif unsuccessful: ' + error);\r\n        }\r\n    });\r\n\r\nTake a look at tests/animated-gif/animated-gif-async.js file to see how it works in\r\na real example.\r\n\r\n\r\nHow to Install?\r\n---------------\r\n\r\nTo compile the module, make sure you have giflib [1] and run:\r\n\r\n    node-waf configure build\r\n\r\nThis will produce gif.node object file. Don't forget to point NODE_PATH to\r\nnode-gif directory to use it.\r\n\r\nAnother way to get it installed is to use node.js package manager npm [2]. To\r\nget node-gif installed via npm, run:\r\n\r\n    npm install gif\r\n\r\nThis will take care of everything and you don't need to worry about NODE_PATH.\r\n\r\n[1]: http://sourceforge.net/projects/giflib/\r\n\r\n\r\nWondering about PNG or JPEG?\r\n----------------------------\r\n\r\nWonder no more, I also wrote modules to produce PNG and JPEG images.\r\nHere they are:\r\n\r\n    http://github.com/pkrumins/node-png\r\n    http://github.com/pkrumins/node-jpeg\r\n\r\n\r\n","funding_links":[],"categories":["TODO scan for Android support in followings","C++","Libraries","etc"],"sub_categories":["C++"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkrumins%2Fnode-gif","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkrumins%2Fnode-gif","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkrumins%2Fnode-gif/lists"}