{"id":39582827,"url":"https://github.com/ssnangua/sharp-ico","last_synced_at":"2026-01-18T07:31:46.363Z","repository":{"id":53300391,"uuid":"521362259","full_name":"ssnangua/sharp-ico","owner":"ssnangua","description":"ICO encoder and decoder for sharp base on ico-endec and decode-ico.","archived":false,"fork":false,"pushed_at":"2022-08-30T08:36:28.000Z","size":154,"stargazers_count":15,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T22:39:44.680Z","etag":null,"topics":["convert","decode","encode","ico","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-08-04T17:45:02.000Z","updated_at":"2025-05-26T05:53:41.000Z","dependencies_parsed_at":"2022-09-02T02:00:25.821Z","dependency_job_id":null,"html_url":"https://github.com/ssnangua/sharp-ico","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ssnangua/sharp-ico","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnangua%2Fsharp-ico","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnangua%2Fsharp-ico/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnangua%2Fsharp-ico/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnangua%2Fsharp-ico/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssnangua","download_url":"https://codeload.github.com/ssnangua/sharp-ico/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnangua%2Fsharp-ico/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":["convert","decode","encode","ico","image","sharp"],"created_at":"2026-01-18T07:31:46.272Z","updated_at":"2026-01-18T07:31:46.343Z","avatar_url":"https://github.com/ssnangua.png","language":"JavaScript","readme":"# sharp-ico\n\nICO encoder and decoder for [sharp](https://www.npmjs.com/package/sharp) base on [ico-endec](https://www.npmjs.com/package/ico-endec) (for encode) and [decode-ico](https://www.npmjs.com/package/decode-ico) (for decode).\n\n## Install\n\n```bash\nnpm install sharp-ico\n```\n\n## Usage\n\n### Create instances of sharp from an ICO image\n\n#### `ico.sharpsFromIco(input, options?, resolveWithObject?)`\n\n- `input` (string | Buffer) - A String containing the filesystem path to an ICO image file, or a Buffer containing ICO image data.\n- `options` Object (optional) - sharp constructor [options](https://sharp.pixelplumbing.com/api-constructor#parameters).\n- `resolveWithObject` boolean (optional) - Return an array of Object containing `image` (instance of sharp) property and [decoding info](#decodinginfo) instead of only instance of sharp. Default by `false`.\n\nReturns `Sharp[] | ImageData[]` - Return an array of instance of sharp or Object containing `image` (instance of sharp) property and [decoding info](#decodinginfo).\n\n```js\nconst ico = require(\"sharp-ico\");\n\nico\n  .sharpsFromIco(\"input.ico\", {\n    // sharp constructor options\n  }) // returns an array of instance of sharp\n  .forEach(async (icon, index) =\u003e {\n    icon.toFile(`output-${index}.png`);\n\n    // Or\n    const metadata = await icon.metadata();\n    icon.toFile(`output-${metadata.width}x${metadata.height}.png`);\n  });\n\n// Set the third option to `true`, will return objects with decoding info\nico\n  .sharpsFromIco(\"input.ico\", null, true)\n  .forEach((icon) =\u003e {\n    icon.image.toFile(`output-${icon.width}x${icon.height}.png`);\n  });\n```\n\n### Write an ICO file\n\n#### `ico.sharpsToIco(icons, fileOut, options?)`\n\n- `icons` Sharp[] - An array of instance of sharp.\n- `fileOut` string - The path to write the image data to.\n- `options` Object (optional)\n  - `sizes` (number[] | `\"default\"`) - Array of sizes to use when resizing. `\"default\"` equal to `[256, 128, 64, 48, 32, 24, 16]`.\n  - `resizeOptions` Object (optional) - sharp resize [options](https://sharp.pixelplumbing.com/api-resize#parameters).\n\nReturns `Promise\u003cObject\u003e` - Resolve with an Object containing `size`, `width`, `height` properties.\n\n```js\nconst sharp = require(\"sharp\");\nconst ico= require(\"sharp-ico\");\nconst bmp = require(\"sharp-bmp\"); // if need to write bmp icons\n\nico\n  .sharpsToIco(\n    [\n      sharp(\"input-256x256.png\"),\n      bmp.sharpFromBmp(\"input-64x64.bmp\"),\n      sharp(\"input-32x32.png\"),\n      // more sizes...\n    ],\n    \"output.ico\"\n  )\n  .then((info) =\u003e {\n    console.log(info); // { size, width, height }\n  })\n  .catch((err) =\u003e {\n    console.error(err);\n  });\n\n// sizes options\nico\n  .sharpsToIco(\n    [\n      sharp(\"input-256x256.png\")\n    ],\n    \"output.ico\",\n    {\n      sizes: [64, 32, 24],\n      // sizes: \"default\", // equal to [256, 128, 64, 48, 32, 24, 16]\n      resizeOptions: {}, // sharp resize optinos\n    }\n  ); // will output a 64x64 ico image (with 32x32 and 24x24 sizes)\n```\n\n### Decode ICO\n\n#### `ico.decode(buffer)`\n\n- `buffer` Buffer - A Buffer containing ICO image data.\n\nReturns `Object[]` - Return an array of Object contains the following \u003cspan id=\"decodinginfo\"\u003edecoding info\u003c/span\u003e:\n\n- `width` number - The width of the image, in pixels.\n- `height` number - The height of the image, in pixels.\n- `type` string - The type of image, will be one of `bmp` or `png`.\n- `data` Uint8Array - The data of the image, format depends on type, see below.\n- `bpp` number - The color depth of the image as the number of bits used per pixel.\n- `hotspot` null | { x: number, y: number } - If the image is a cursor (.cur), this is the hotspot.\n\nThe format of the `data` parameter depends on the `type` of image. When the image is of type `bmp`, the data array will hold raw pixel data in the RGBA order, with integer values between 0 and 255 (included). When the type is `png`, the array will be png data.\n\n```js\nconst fs = require(\"fs\");\nconst sharp = require(\"sharp\");\nconst ico = require(\"sharp-ico\");\n\nconst buffer = fs.readFileSync(\"input.ico\");\nconst icons = ico.decode(buffer);\n\nicons.forEach((icon) =\u003e {\n  const image = icon.type === \"png\"\n    ? sharp(icon.data)\n    : sharp(icon.data, {\n        raw: {\n          width: icon.width,\n          height: icon.height,\n          channels: 4,\n        },\n      });\n  image.toFile(`output-${icon.width}x${icon.height}.png`);\n});\n```\n\n### Encode ICO\n\n#### `ico.encode(bufferList)`\n\n- `bufferList` Buffer[] - An array of Buffer containing PNG or BMP image data.\n\nReturns `Buffer` - Return a buffer containing ICO image data.\n\n```js\nconst fs = require(\"fs\");\nconst sharp = require(\"sharp\");\nconst ico = require(\"sharp-ico\");\nconst bmp = require(\"sharp-bmp\"); // if need to write bmp icons\n\n(async () =\u003e {\n  const icons = [\n    sharp(\"input-256x256.png\"),\n    bmp.sharpFromBmp(\"input-64x64.bmp\"),\n    sharp(\"input-32x32.png\"),\n  ];\n  const bufferList = [];\n  for (let i = 0; i \u003c icons.length; i++) {\n    const buffer = await icons[i].toFormat(\"png\").toBuffer();\n    bufferList.push(buffer);\n  }\n  const icoBuffer = ico.encode(bufferList);\n  fs.writeFileSync(\"output.ico\", icoBuffer);\n\n  console.log(icoBuffer.length); // size of output.ico\n})();\n```\n\n## Change Log\n\n### 0.1.1\n\n- `sharpsToIco` support `sizes` option\n\n### 0.1.5\n\n- Use [decode-ico](https://www.npmjs.com/package/decode-ico) instead of [ico-endec](https://www.npmjs.com/package/ico-endec) for decoding to support transparent bmp icons.\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssnangua%2Fsharp-ico","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssnangua%2Fsharp-ico","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssnangua%2Fsharp-ico/lists"}