{"id":29749088,"url":"https://github.com/jeffrey-mu/webp-batch-convert-p","last_synced_at":"2026-05-18T00:09:51.581Z","repository":{"id":59728340,"uuid":"538780626","full_name":"Jeffrey-mu/webp-batch-convert-p","owner":"Jeffrey-mu","description":"webp 图片批量转换。将指定目录内 png/jpg/jpeg/bmp/gif 格式的图片批量转换为 webp 格式。","archived":false,"fork":false,"pushed_at":"2022-09-27T10:31:08.000Z","size":2928,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-25T09:58:09.740Z","etag":null,"topics":["batch","cwebp","node","webp"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Jeffrey-mu.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":"2022-09-20T02:38:31.000Z","updated_at":"2022-09-20T04:05:35.000Z","dependencies_parsed_at":"2023-01-18T23:45:57.446Z","dependency_job_id":null,"html_url":"https://github.com/Jeffrey-mu/webp-batch-convert-p","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Jeffrey-mu/webp-batch-convert-p","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeffrey-mu%2Fwebp-batch-convert-p","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeffrey-mu%2Fwebp-batch-convert-p/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeffrey-mu%2Fwebp-batch-convert-p/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeffrey-mu%2Fwebp-batch-convert-p/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jeffrey-mu","download_url":"https://codeload.github.com/Jeffrey-mu/webp-batch-convert-p/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeffrey-mu%2Fwebp-batch-convert-p/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267161474,"owners_count":24045475,"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-07-26T02:00:08.937Z","response_time":62,"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":["batch","cwebp","node","webp"],"created_at":"2025-07-26T11:42:59.332Z","updated_at":"2026-05-18T00:09:51.554Z","avatar_url":"https://github.com/Jeffrey-mu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Webp Batch Convert\n========\nwebp 图片批量转换。将指定目录内 png/jpg/jpeg/bmp/gif 格式的图片批量转换为 webp 格式。\n\n\u003e 该工具是基于[lzwme/webp-batch-convert](https://github.com/lzwme/webp-batch-convert)二次开发, 添加一些配置项,以及细节优化。\n```mk\n### 新增配置\n1. replace_suffix: true, 开启替换webp后缀，默认保留源文件后缀。\n2. gif: true 过滤gif图片, 直接将gif图片copy到新文件夹，保留动效。\n3. cover: true 开启后强制覆盖，默认跳过，如图片已被转换则跳过。\n4. del_old_dir: true 开启删除当前文件夹，将格式化后目录名改为已删除文件夹名。\n\n### 优化\n1. 当文件超出一定数量 递归执行会造成内存溢出 需要优化 递归调用方式\n“事件驱动” （Event-Driven）的特性\n在 JavaScript 中，由于其 “事件驱动” （Event-Driven）的特性，使用 \"setTimeout\"、 “nextTick” 等方式对指定函数的调用，实际上是将该函数的引用（指针）储存起来，并在适当的时候调用。[参考](https://github.com/pfan123/Articles/issues/50)。\n2. 空文件过滤，file.size 为零判空。\n3. 目标嵌套目录可深度工作。\n```\n## 快速上手\n\n### 在项目目录中安装\n\n```bash\nnpm install --save-dev webp-batch-convert-p\n```\n\n### 使用示例(nodejs 模块 API 方式)\n\n```js\n//import convert from 'webp-batch-convert-p';\nconst convert = require('webp-batch-convert-p');\nlet res;\n\n// 示例一: 生成 img 目录下的图片文件至 webp 目录\nres = 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    replace_suffix: true\n};\n// 清空输出目录\nconvert.utils.delDir('./webp');\nres = convert.cwebp('./img','./webp', cwebpOpts);\nconsole.log('total: ', res);\n```\n\n### `best-practice`\n\n- [https://github.com/Jeffrey-mu/webp-batch-convert-p/tree/master/best-practice](https://github.com/Jeffrey-mu/webp-batch-convert-p/tree/master/best-practice)\n\n## 命令行方式使用(cwebp-batch)\n\n### 全局安装\n\n```js\nnpm install -g webp-batch-convert-p\n```\n\n### 使用示例\n\n```js\ncwebp-batch --in img-folder --out webp-folder \u003c-q 75 -quiet\u003e\n```\n或者局部安装，然后如下方式使用：\n```js\n./node_modules/.bin/cwebp-batch --in img-folder --out webp-folder \u003c-q 75 -quiet\u003e\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 = convert.cwebp('./img','./webp', {\n    quiet: true, // 不输出详情\n    q: 60        // 质量\n});\nconsole.log('total: ' + 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 后缀的文件\nconvert.utils.delDir('./webp', /\\.webp$/);\n```\n\n## 二次开发\n\n- 依赖安装 `yarn install`\n- 修改/新增功能\n- 添加测试并执行 `yarn test`\n- `cwebp-batch` 命令行命令全局安装与测试 `npm i -g ./`\n\n## License\n\n`webp-batch-convert-p` is released under the MIT license.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffrey-mu%2Fwebp-batch-convert-p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffrey-mu%2Fwebp-batch-convert-p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffrey-mu%2Fwebp-batch-convert-p/lists"}