{"id":23602816,"url":"https://github.com/lzwme/webp-batch-convert","last_synced_at":"2026-03-18T00:03:01.088Z","repository":{"id":62202239,"uuid":"80494557","full_name":"lzwme/webp-batch-convert","owner":"lzwme","description":"webp 图片批量转换。将 png/jpg/bmp 格式的图片批量转换为 webp 格式。","archived":false,"fork":false,"pushed_at":"2023-01-28T14:47:28.000Z","size":298,"stargazers_count":81,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-08T21:48:55.281Z","etag":null,"topics":["javascript","lzwme","node","nodejs","webp"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/lzwme.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-01-31T05:36:53.000Z","updated_at":"2025-03-31T01:39:27.000Z","dependencies_parsed_at":"2023-02-15T17:01:12.569Z","dependency_job_id":null,"html_url":"https://github.com/lzwme/webp-batch-convert","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lzwme%2Fwebp-batch-convert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lzwme%2Fwebp-batch-convert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lzwme%2Fwebp-batch-convert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lzwme%2Fwebp-batch-convert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lzwme","download_url":"https://codeload.github.com/lzwme/webp-batch-convert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253154954,"owners_count":21862618,"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":["javascript","lzwme","node","nodejs","webp"],"created_at":"2024-12-27T12:13:21.527Z","updated_at":"2026-03-18T00:03:01.071Z","avatar_url":"https://github.com/lzwme.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![webp-batch-convert](https://nodei.co/npm/webp-batch-convert.png)](https://npmjs.com/package/webp-batch-convert)\n\nWebp Batch Convert\n========\nwebp 图片批量转换。将指定目录内 png/jpg/jpeg/bmp/gif 格式的图片批量转换为 webp 格式。\n\n[![NPM version][npm-image]][npm-url]\n[![node version][node-image]][node-url]\n[![npm download][download-image]][download-url]\n[![GitHub issues][issues-img]][issues-url]\n[![GitHub forks][forks-img]][forks-url]\n[![GitHub stars][stars-img]][stars-url]\n[![minzipped size][bundlephobia-img]][bundlephobia-url]\n\n[stars-img]: https://img.shields.io/github/stars/lzwme/webp-batch-convert.svg\n[stars-url]: https://github.com/lzwme/webp-batch-convert/stargazers\n[forks-img]: https://img.shields.io/github/forks/lzwme/webp-batch-convert.svg\n[forks-url]: https://github.com/lzwme/webp-batch-convert/network\n[issues-img]: https://img.shields.io/github/issues/lzwme/webp-batch-convert.svg\n[issues-url]: https://github.com/lzwme/webp-batch-convert/issues\n[npm-image]: https://img.shields.io/npm/v/webp-batch-convert.svg?style=flat-square\n[npm-url]: https://npmjs.com/package/webp-batch-convert\n[node-image]: https://img.shields.io/badge/node.js-%3E=_12-green.svg?style=flat-square\n[node-url]: https://nodejs.org/download/\n[download-image]: https://img.shields.io/npm/dm/webp-batch-convert.svg?style=flat-square\n[download-url]: https://npmjs.com/package/webp-batch-convert\n[bundlephobia-url]: https://bundlephobia.com/result?p=webp-batch-convert@latest\n[bundlephobia-img]: https://badgen.net/bundlephobia/minzip/webp-batch-convert@latest\n\n## 快速上手\n\n### 在项目目录中安装\n\n```bash\nnpm install --save-dev webp-batch-convert\nnpm exec wbc -h\n```\n\n### 使用示例(nodejs 模块 API 方式)\n\n```js\n//import convert from 'webp-batch-convert';\nconst convert = require('webp-batch-convert');\nlet res;\n\n// 示例一: 生成 img 目录下的图片文件至 webp 目录\nres = await convert.cwebp('./img', './webp');\nconsole.log('total: ', res);\n\n// 示例二: 生成 img 目录下的图片文件至 webp 目录，附带质量等参数\n// 更多参数参考：https://developers.google.com/speed/webp/docs/cwebp?csw=1#options\n// 也可以执行如下命令通过 cwebp 帮助信息了解： `yarn cwebp --longhelp`\nconst cwebpOpts = {\n    /** don't print anything */\n    quiet: true,\n    /** quality factor (0:small..100:big), default=75 */\n    q: 75,\n    /** transparency-compression quality (0..100), default=100 */\n    alpha_q: 100,\n    /** spatial noise shaping (0:off, 100:max), default=50 */\n    sns: 50,\n    /** filter strength (0=off..100), default=60 */\n    f: 60,\n    /** use simple filter instead of strong */\n    nostrong: false,\n};\n// 先清空输出目录\nconvert.utils.delDir('./webp');\nres = await convert.cwebp('./img','./webp', cwebpOpts);\nconsole.log('total: ', res);\n```\n\n### `best-practice`\n\n- [https://github.com/lzwme/webp-batch-convert/tree/master/best-practice](https://github.com/lzwme/webp-batch-convert/tree/master/best-practice)\n\n## 命令行方式使用(wbc / cwebp-batch)\n\n### 全局安装\n\n```bash\nnpm install -g webp-batch-convert\nwbc -h\n# or \ncwebp-batch -h\n```\n\n也可以不安装，使用 `npx` 执行：\n\n```bash\nnpx webp-batch-convert -h\n```\n\n### 使用示例\n\n```js\nwbc --in img-folder --out webp-folder \u003c--debug --q 75\u003e\n```\n\n或者局部安装，然后如下方式使用：\n\n```js\n./node_modules/.bin/wbc --in img-folder --out webp-folder \u003c-D -q 75\u003e\n```\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://cdn.rawgit.com/lzwme/webp-batch-convert/master/test/img/snapshot.png\"\u003e\n\u003c/p\u003e\n\n## API\n\n- `.cwebp(imgDir, webpDir, cwebpOptions)`\n\n批量转换生成 webp。示例：\n```js\n// 将 img 目录下的所有图片转换为 webp 文件，输出至 webp 目录\nconst res = await convert.cwebp('./img','./webp', {\n    debug: true,\n    q: 60        // 质量\n});\nconsole.log('result: ' + res);\n```\n\n- `.utils.mkDir(dirPath)`\n\n创建一个(深度的)目录。示例：\n```js\n// 创建目录\nconvert.utils.mkDir('./src/assets/webp');\n```\n\n- `.utils.delDir(dirPath, ext)`\n\n清空一个（非空的）目录。示例：\n```js\n// 删除 webp 目录\nconvert.utils.delDir('./webp');\n// 删除 webp 目录下的所有 webp 后缀的文件\nconvert.utils.delDir('./webp', 'webp');\n// 删除 webp 目录下的所有 .webp、png 后缀的文件\nconvert.utils.delDir('./webp', /\\.(webp|png)$/);\n```\n\n## 二次开发\n\n- 依赖安装 `pnpm install`\n- 修改/新增功能\n- 添加测试并执行 `pnpm test`\n- 全局安装与测试 `npm link . \u0026\u0026 wbc -h`\n\n## License\n\n`webp-batch-convert` is released under the MIT license.\n\n该插件由[志文工作室](https://lzw.me)开发和维护。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flzwme%2Fwebp-batch-convert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flzwme%2Fwebp-batch-convert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flzwme%2Fwebp-batch-convert/lists"}