{"id":39582773,"url":"https://github.com/ssnangua/sharp-gif","last_synced_at":"2026-01-18T07:31:44.145Z","repository":{"id":58373694,"uuid":"531479287","full_name":"ssnangua/sharp-gif","owner":"ssnangua","description":"Generate animated GIF/WebP for sharp base on gif-encoder.","archived":false,"fork":false,"pushed_at":"2022-09-08T02:56:20.000Z","size":83,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-09T02:47:40.883Z","etag":null,"topics":["animated","convert","encode","gif","image","sharp"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ssnangua.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-01T10:59:56.000Z","updated_at":"2025-01-08T23:15:28.000Z","dependencies_parsed_at":"2023-01-18T00:30:39.874Z","dependency_job_id":null,"html_url":"https://github.com/ssnangua/sharp-gif","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ssnangua/sharp-gif","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnangua%2Fsharp-gif","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnangua%2Fsharp-gif/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnangua%2Fsharp-gif/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnangua%2Fsharp-gif/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssnangua","download_url":"https://codeload.github.com/ssnangua/sharp-gif/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnangua%2Fsharp-gif/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28533167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["animated","convert","encode","gif","image","sharp"],"created_at":"2026-01-18T07:31:44.044Z","updated_at":"2026-01-18T07:31:44.118Z","avatar_url":"https://github.com/ssnangua.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Note:** you can try [sharp-gif2](https://www.npmjs.com/package/sharp-gif2) first, it is base on [gifenc](https://www.npmjs.com/package/gifenc), has faster encoding speed.\n\n---\n\n# sharp-gif\n\nGenerate animated GIF/WebP for [sharp](https://www.npmjs.com/package/sharp) base on [gif-encoder](https://www.npmjs.com/package/gif-encoder).\n\n![](1.gif) + ![](2.gif) + ![](3.gif) = ![](output/concat.gif)\n\n## Install\n\n```bash\nnpm install sharp-gif\n```\n\n## Usage\n\n### Generate animated GIF\n\n```js\nconst fs = require(\"fs\");\nconst sharp = require(\"sharp\");\nconst GIF = require(\"sharp-gif\");\n\n(async () =\u003e {\n  // Simple use case\n  const image = await GIF\n    .createGif()\n    .addFrame([\n      sharp(\"./frames/0000.png\"),\n      sharp(\"./frames/0001.png\"),\n      sharp(\"./frames/0002.png\"),\n    ])\n    .toSharp();\n  image.toFile(\"./frames.gif\");\n  // Can also generate an animated WebP\n  image.toFile(\"./frames.webp\");\n\n  // Options\n  const gif = GIF.createGif({\n    // GifEncoder constructor options\n    gifEncoderOptions: { highWaterMark: 64 },\n    // Sharp constructor options\n    sharpOptions: {},\n    // Custom size\n    width: 300,\n    height: 200,\n    // Amount of milliseconds to delay between frames\n    delay: 200,\n    // Amount of times to repeat GIF\n    repeat: 0,\n    // GIF quality\n    quality: 10,\n    // Define the color which represents transparency in the GIF.\n    transparent: \"#FFFFFF\",\n    // Resize all frame to `largest` or `smallest`\n    resizeTo: \"largest\",\n    // Resize by `zoom` or `crop`\n    resizeType: \"zoom\",\n    // Options for sharp.resize()\n    resizeOptions: {},\n    // Background option for sharp.extend()\n    extendBackground: { r: 0, g: 0, b: 0, alpha: 0 },\n  });\n  gif.addFrame(sharp(\"./1.png\"));\n  gif.addFrame(sharp(\"./2.png\"));\n  const image = await gif.toSharp();\n  image.toFile(\"./frames.gif\");\n\n  // Trace encoding progress\n  const image = await GIF\n    .createGif()\n    .addFrame(\n      fs.readdirSync(\"./frames\")\n        .map((file) =\u003e sharp(`./frames/${file}`))\n    )\n    .toSharp(({ total, encoded }) =\u003e {\n      console.log(`${encoded}/${total}`);\n    });\n  image.toFile(\"./frames.gif\");\n\n  // You can even concat animated GIFs\n  const image = await GIF\n    .createGif({ transparent: \"#FFFFFF\", })\n    .addFrame([\n      sharp(\"./1.gif\", { animated: true }),\n      sharp(\"./2.gif\", { animated: true }),\n    ])\n    .toSharp();\n  image.toFile(\"./concat.gif\");\n})();\n```\n\n### Processing GIF frames\n\n```js\nconst sharp = require(\"sharp\");\nconst GIF = require(\"sharp-gif\");\n\n(async () =\u003e {\n  const reader = GIF.readGif(sharp(\"./2.gif\", { animated: true }));\n  const frames = await reader.toFrames();\n  frames.forEach((frame, index) =\u003e {\n    // You can process each frame here\n\n    // Or just simple output frame\n    frame.toFile(`./output/${(\"000\" + index).substr(-4)}.png`);\n  });\n\n  const gif = await reader.toGif({ transparent: \"#FFFFFF\", });\n  const image = await gif.toSharp();\n  image.toFile(\"./output/remake.gif\");\n})();\n```\n\n## API\n\n### `GIF.createGif(options?: Object): Gif`\n\n- `options` Object _(optional)_\n  - `gifEncoderOptions` Object _(optional)_ - GifEncoder constructor options.\n    - `highWaterMark` Number - Number, in bytes, to store in internal buffer. Defaults to 64kB.\n  - `sharpOptions` Object _(optional)_ - Sharp constructor [options](https://sharp.pixelplumbing.com/api-constructor#parameters).\n  - `width` Number _(optional)_ - Width, in pixels, of the GIF to output.\n  - `height` Number _(optional)_ - Height, in pixels, of the GIF to output.\n  - `delay` Number _(optional)_ - Amount of milliseconds to delay between frames.\n  - `repeat` Number _(optional)_ - Amount of times to repeat GIF. Default by `0`, loop indefinitely.\n  - `quality` Number _(optional)_ - GIF quality. `1` is best colors and worst performance, `20` is suggested maximum but there is no limit. Default by `10`.\n  - `transparent` String _(optional)_ - Define the color which represents transparency in the GIF.\n  - `resizeTo` (\"largest\" | \"smallest\") _(optional)_ - Resize all frame to the `largest` frame or `smallest` frame size. Default by `largest`.\n  - `resizeType` (\"zoom\" | \"crop\") _(optional)_ - `zoom` use sharp.resize(), `crop` use sharp.extend() and sharp.extract().\n  - `resizeOptions` [sharp.ResizeOptions](https://sharp.pixelplumbing.com/api-resize#parameters) _(optional)_ - Options for sharp.resize().\n  - `extendBackground` [sharp.Color](https://www.npmjs.org/package/color) _(optional)_ - Background option for sharp.extend().\n\nReturns `Gif` - Return a instance of Gif Contains the following methods:\n\n#### `gif.addFrame(frame: Sharp | Sharp[]): Gif`\n\n- `frame` (Sharp | Sharp[]) - An instance of Sharp, or an array of instance of Sharp.\n\nReturns `Gif` - Return the Gif instance for chaining.\n\n#### `gif.toSharp(progress?: Function, encoder?: GifEncoder): Promise\u003cSharp\u003e`\n\nEncode all frames and resolve with an animated Sharp instance.\n\n- `progress` (info: Object) =\u003e void _(optional)_ - Frames encoding progress.\n  - `info` Object - **Note** that the frames count contains GIF header end footer (as 2 frames).\n    - `total` Number - Total frames count.\n    - `encoded` Number - Encoded frames count.\n- `encoder` GifEncoder _(optional)_ - Custom GifEncoder.\n\nReturns `Promise\u003cSharp\u003e` - Resolve with an instance of Sharp.\n\n#### `gif.toBuffer(progress?: Function, encoder?: GifEncoder): Promise\u003cBuffer\u003e`\n\nEncode all frames and resolve with an animated GIF buffer.\n\n#### `gif.getEncoder(width: Number, height: Number, options?: Object): GIFEncoder`\n\nReturn a new instance of GIFEncoder. See [new GifEncoder](https://github.com/twolfson/gif-encoder#new-gifencoderwidth-height-options).\n\n### `GIF.readGif(image: Sharp): GifReader`\n\n- `image` Sharp - An instance of Sharp\n\nReturns `GifReader` - Return a instance of GifReader Contains the following methods:\n\n#### `reader.toFrames(): Promise\u003cSharp[]\u003e`\n\nCut GIF frames.\n\nReturns `Promise\u003cSharp[]\u003e` - Resolve with cutted frames (an array of instance of Sharp).\n\n#### `reader.toGif(options?: Object): Promise\u003cGif\u003e`\n\nCreate Gif from cutted frames.\n\n- `options` Object _(optional)_ - Options for createGif(). See [createGif](#gifcreategifoptions-object-gif).\n\nReturns `Promise\u003cGif\u003e` - Resolve with an instance of Gif.\n\nA shortcut to create a Gif with the cutted frames, equal to:\n\n`GIF.createGif(options).addFrame(reader.frames || (await reader.toFrames()));`\n\n## Change Log\n\n### 0.1.3\n\n- Feature: Add `GifReader` for cutting frames.\n\n### 0.1.5\n\n- Fix: Resize bug.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssnangua%2Fsharp-gif","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssnangua%2Fsharp-gif","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssnangua%2Fsharp-gif/lists"}