{"id":30830252,"url":"https://github.com/nieyuyao/webp-wasm","last_synced_at":"2026-03-02T04:13:29.969Z","repository":{"id":231485557,"uuid":"780218586","full_name":"nieyuyao/webp-wasm","owner":"nieyuyao","description":"A webp wasm library based on libwebp.","archived":false,"fork":false,"pushed_at":"2025-02-07T02:05:15.000Z","size":1113,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-06T12:21:48.814Z","etag":null,"topics":["animation","decoder","encoder","javascript","libwebp","wasm","webassembly","webp"],"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/nieyuyao.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-04-01T02:11:06.000Z","updated_at":"2025-07-10T10:04:27.000Z","dependencies_parsed_at":"2024-04-15T13:44:59.392Z","dependency_job_id":null,"html_url":"https://github.com/nieyuyao/webp-wasm","commit_stats":null,"previous_names":["nieyuyao/webp-wasm"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/nieyuyao/webp-wasm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nieyuyao%2Fwebp-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nieyuyao%2Fwebp-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nieyuyao%2Fwebp-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nieyuyao%2Fwebp-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nieyuyao","download_url":"https://codeload.github.com/nieyuyao/webp-wasm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nieyuyao%2Fwebp-wasm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273926553,"owners_count":25192318,"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","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"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":["animation","decoder","encoder","javascript","libwebp","wasm","webassembly","webp"],"created_at":"2025-09-06T15:52:21.649Z","updated_at":"2026-03-02T04:13:29.963Z","avatar_url":"https://github.com/nieyuyao.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webp.wasm\n\nwebp.wasm is a pure Webassembly / Javascript port of libwebp. The library supports encoding animated WebP.\n\n![CI](https://github.com/nieyuyao/webp-wasm/workflows/CI/badge.svg)\n![latest tag](https://badgen.net/github/release/nieyuyao/webp-wasm)\n![npm](https://img.shields.io/npm/v/wasm-webp.svg)\n\n## Install\n\n```shell\nnpm i wasm-webp\n```\n\n## APIs\n\n### Encode\n\n#### encode\n\nGet encoder encoderVersion.\n\n`function encoderVersion(): Promise\u003cstring\u003e`\n\n##### Example\n\n```javascript\nconst version = await encoderVersion()\nconsole.log(version) // 1.3.2\n```\n\n#### encodeRGB\n\nEncodes rgb bitmap an returns WebP Uint8Array. The `width` and `height` parameters of the bitmap should be provided.\n\n`function encodeRGB(rgb: Uint8Array, width: number, height: number, quality?: number): Promise\u003cNullable\u003cUint8Array\u003e\u003e`\n\n##### Example\n\n```javascript\n...\nconst ctx = canvas.getContext('2d')!\nconst imgData = ctx.getImageData(0, 0, canvas.width, canvas.height)\nconst buf = new Uint8Array(3 * canvas.width, canvas.height) \nlet j = 0\n// remove alpha\nimgData.data.forEach((pixel, i) =\u003e {\n  if ((i + 1) % 4 === 0) {\n    return\n  }\n  buf[j] = pixel\n  j++\n})\nconst webpData = await encodeRGB(buf, canvas.width, canvas.height)\nconst blob = new Blob([webpData!], {type: 'image/webp'})\nconst blobURL = URL.createObjectURL(blob);\n// download webp\nconst a = document.createElement('a')\na.download = '1.webp'\na.href = blobURL\ndocument.body.appendChild(a)\na.click()\na.remove()\n```\n\n#### encodeRGBA\n\nEncodes rgba bitmap an returns WebP Uint8Array.\n\n`function encodeRGBA(rgba: Uint8Array, width: number, height: number, quality?: number): Promise\u003cNullable\u003cUint8Array\u003e\u003e`\n\n##### Example\n\n```javascript\n...\nconst ctx = canvas.getContext('2d')!\nconst imgData = ctx.getImageData(0, 0, canvas.width, canvas.height)\nconst webpData = await encodeRGBA(imgData.data, canvas.width, canvas.height)\n// download webp\n...\n```\n\n #### encode\n\nA more advanced API is based on the WebPConfig. \u003cb\u003eOnly the lossless and quality parameters are supported now !!!\u003c/b\u003e. You can generate low-quality webp with this function.\n\n`function encodeRGBA(data: Uint8Array, width: number, height: number, hasAlpha: boolean,config: Partial\u003cWebPConfig\u003e): Promise\u003cNullable\u003cUint8Array\u003e\u003e`\n\n- hasAlpha: `boolean`\n\nWhether to include alpha chanel.\n\n- WebPConfig.lossless: `number`\n\nLossless encoding (0=lossy(default), 1=lossless).\n\n- WebPConfig.quality: `number`\n\nBetween 0 and 100. Default value is 100.\n\n##### Example\n\n```javascript\n...\nconst ctx = canvas.getContext('2d')!\nconst imgData = ctx.getImageData(0, 0, canvas.width, canvas.height)\nconst webpData = await encode(imgData.data, canvas.width, canvas.height, true, { lossless: 0 })\n// download webp\n...\n```\n\n#### encodeAnimation\n\nReturns animated WebP like `GIF`.\n\n`function encodeAnimation(width: number, height: number, hasAlpha: boolean, frames: WebPAnimationFrame[]): Promise\u003cNullable\u003cUint8Array\u003e\u003e`\n\n- hasAlpha: `boolean`\n\nWhether to include alpha chanel.\n\nThe WebPAnimationFrame has follow properties:\n\n- WebPAnimationFrame.data: `Uint8Array`\n\nFrame bitmap.\n\n- WebPAnimationFrame.duration: `number`\n\nDuration of frame.\n\n- WebPAnimationFrame.config: `WebPConfig` (optional)\n\nPer-frame encoding configuration. If not provided, default config is used (lossless: 0, quality: 100).\n\n##### Example\n\n```javascript\n...\n// record each frame\nframes.push({\n  data: ctx.getImageData(0, 0, 100, 100).data,\n  duration: 20\n})\n// with per-frame config\nframes.push({\n  data: ctx.getImageData(0, 0, 100, 100).data,\n  duration: 20,\n  config: { lossless: 0, quality: 80 }\n})\nconst webpData = await encodeAnimation(100, 100, true, frames)\n...\n// download webp\n```\n\n### Decode\n\n#### decoderVersion\n\nGet decoder version.\n\n`function decoderVersion(): Promise\u003cstring\u003e`\n\n##### Example\n\n```javascript\nconst version = await decoderVersion()\nconsole.log(version) // 1.3.2\n```\n\n#### decodeRGB\n\nDecodes webp and outputs `WebPDecodedImageData` contains rgb bitmap.\n\n`function decodeRGB(data: Uint8Array): Promise\u003cNullable\u003cWebPDecodedImageData\u003e\u003e`\n\n##### Example\n\n```javascript\n...\nconst fr = new FileReader()\nfr.onload = () =\u003e {\n  if (!fr.result) {\n    return\n  }\n  webpData = fr.result as Uint8Array\n  const result = await decodeRGB(webpData)\n  // draw imageData\n  const ctx = canvas.getContext('2d')!\n\tctx.clearRect(0, 0, canvas.width, canvas.height)\n\tcanvas.style.width = `${result.width}px`\n\tcanvas.style.height = `${result.height}px`\n\tcanvas.width = result.width\n\tcanvas.height = result.height\n\tctx.putImageData(new ImageData(new Uint8ClampedArray(result.data)), 0, 0)\n}\n// read webp file\nfr.readAsArrayBuffer(file)\n...\n```\n\n#### decodeRGBA\n\nDecodes webp and outputs `WebPDecodedImageData` contains rgba bitmap.\n\n`function decodeRGB(data: Uint8Array): Promise\u003cNullable\u003cWebPDecodedImageData\u003e\u003e`\n\n##### Example\n\n```javascript\n...\nconst fr = new FileReader()\nfr.onload = () =\u003e {\n  if (!fr.result) {\n    return\n  }\n  webpData = fr.result as Uint8Array\n  const result = await decodeRGBA(webpData)\n  // draw imageData\n  ...\n}\n// webp file\nfr.readAsArrayBuffer(file)\n...\n```\n\n#### decodeAnimation\n\nDecoding animated WebP image. Returns an array of frames.\n\n`function decodeAnimation(data: Uint8Array, hasAlpha: boolean): Promise\u003cNullable\u003cDecodedWebPAnimationFrame[]\u003e\u003e`\n\n##### Example\n\n```javascript\n...\nconst fr = new FileReader()\nfr.onload = () =\u003e {\n  if (!fr.result) {\n    return\n  }\n  webpData = fr.result as Uint8Array\n  const result = await decodeRGBA(webpData)\n  // draw imageData\n  ...\n}\n// webp file\nfr.readAsArrayBuffer(file)\n...\n```\n\n#### DecodedWebPAnimationFrame\n\nThe object have the following properties:\n\n- DecodedWebPAnimationFrame.width: `number`\n\nThe frame image width.\n\n- DecodedWebPAnimationFrame.height: `number`\n\nThe frame image height.\n\n- DecodedWebPAnimationFrame.duration: `number`\n\nThe frame display duration.\n\n- DecodedWebPAnimationFrame.data: `Uint8Array`\n\nRaw data in pixels.\n\n#### WebPDecodedImageData\n\nThe object have the following properties:\n\n- WebPDecodedImageData.width: `number`\n\nThe image width in pixels.\n\n- WebPDecodedImageData.height: `number`\n\nThe image height in pixels.\n\n- WebPDecodedImageData.data: `Uint8Array`\n\nRaw data in pixels.\n\n\u003e Note: It has same properties as browser `ImageData` object, but it is not. There is actually no `ImageData` in node.\n\n## Playing Examples\n\n```shell\nnpm run build-wasm:dev \u0026\u0026 npm run dev\n```\n\n## Building\n\n```shell\nnpm run build\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnieyuyao%2Fwebp-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnieyuyao%2Fwebp-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnieyuyao%2Fwebp-wasm/lists"}