{"id":21335196,"url":"https://github.com/jowayyoung/img-master","last_synced_at":"2025-07-12T12:31:12.456Z","repository":{"id":57272508,"uuid":"139133380","full_name":"JowayYoung/img-master","owner":"JowayYoung","description":"An image batch processing tool with multifunctional and unlimited","archived":false,"fork":false,"pushed_at":"2023-11-16T17:40:11.000Z","size":104,"stargazers_count":64,"open_issues_count":1,"forks_count":13,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-30T16:09:16.306Z","etag":null,"topics":["compress","group","image","mark","node","transform"],"latest_commit_sha":null,"homepage":"https://yangzw.vip/source?id=img-master","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/JowayYoung.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":"2018-06-29T09:59:58.000Z","updated_at":"2023-11-28T03:26:42.000Z","dependencies_parsed_at":"2022-08-25T00:11:45.115Z","dependency_job_id":null,"html_url":"https://github.com/JowayYoung/img-master","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JowayYoung%2Fimg-master","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JowayYoung%2Fimg-master/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JowayYoung%2Fimg-master/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JowayYoung%2Fimg-master/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JowayYoung","download_url":"https://codeload.github.com/JowayYoung/img-master/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225820263,"owners_count":17529139,"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":["compress","group","image","mark","node","transform"],"created_at":"2024-11-21T23:41:15.178Z","updated_at":"2024-11-21T23:41:15.866Z","avatar_url":"https://github.com/JowayYoung.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Img Master \u003cimg src=\"https://img.shields.io/badge/img--master-多功能无限制的图像批处理工具-66f.svg\"\u003e\n\n[![author](https://img.shields.io/badge/author-JowayYoung-f66.svg)](https://github.com/JowayYoung/img-master)\n[![version](https://img.shields.io/badge/version-0.0.5-f66.svg)](https://github.com/JowayYoung/img-master)\n[![node](https://img.shields.io/badge/node-%3E%3D%2010.0.0-3c9.svg)](https://github.com/JowayYoung/img-master)\n[![npm](https://img.shields.io/badge/npm-%3E%3D%205.6.0-3c9.svg)](https://github.com/JowayYoung/img-master)\n[![test](https://img.shields.io/badge/test-passing-f90.svg)](https://github.com/JowayYoung/img-master)\n[![build](https://img.shields.io/badge/build-passing-f90.svg)](https://github.com/JowayYoung/img-master)\n[![coverage](https://img.shields.io/badge/coverage-100%25-09f.svg)](https://github.com/JowayYoung/img-master)\n[![license](https://img.shields.io/badge/license-MIT-09f.svg)](https://github.com/JowayYoung/img-master)\n\n\u003e `img-master`是一个多功能无限制的图像批处理工具，提供**压缩**、**分组**、**标记**和**变换**四大批处理功能\n\n### 安装\n\n`npm i -g img-master`\n\n\u003e 安装失败\n\n`img-master`某些功能基于`sharp`，所以在安装过程中可能会失败或报错，请通过以下步骤解围。\n\n- 切换**NPM镜像**为淘宝镜像：`npm config set registry https://registry.npm.taobao.org/`\n- 切换**NPM模块内置Node镜像**为淘宝镜像：`npm config set disturl https://npm.taobao.org/mirrors/node/`\n- 切换**Sharp镜像**为淘宝镜像\n\t- `npm config set sharp_binary_host https://npm.taobao.org/mirrors/sharp/`\n\t- `npm config set sharp_libvips_binary_host https://npm.taobao.org/mirrors/sharp-libvips/`\n- 强制清理缓存：`npm cache clean -f`(曾经安装失败才执行)\n- 重新执行安装命令：`npm i -g img-master`\n\n```!\n若是多账户电脑(公司环境)，请切换到管理员账号下执行npm i -g img-master重新安装\n```\n\n若有兴趣了解`某些模块因NPM镜像问题而安装不上`的解围思路，可查看笔者这篇[《聊聊NPM镜像那些险象环生的坑》](https://juejin.im/post/5edf60d4f265da76b559b6ac)，相信会对你有很大的帮助。\n\n### 使用\n\n命令|缩写|功能|描述\n-|-|-|-\n`img-master compress`|`img-master c`|压缩图像|基于`TinyJPG`或`TinyPNG`进行压缩\n`img-master group`|`img-master g`|分组图像|按照图像`尺寸`、`类型`或`体积`进行分组\n`img-master mark`|`img-master m`|标记图像|基于`Sharp`进行标记，提供交互式问答调用\n`img-master transform`|`img-master t`|变换图像|基于`Sharp`进行变换，提供多配置链式调用\n\n- 推荐使用缩写命令\n- 目前只能处理`JPG`和`PNG`的图像\n- 可遍历根目录下所有多层文件夹里符合条件的图像文件\n- 进入需要处理图像的根目录：`cd my-image`，再根据需求执行以上命令\n\n\u003e 图像压缩\n\n- 使用`https://tinyjpg.com`或`https://tinypng.com`压缩图像会有`20张`的数量限制\n- `img-master c`基于以上两个网站进行压缩，但是通过随机修改请求头的`X-Forwarded-For`绕过其数量限制\n\n\u003e 图像变换\n\n- 特点：执行命令可追加多个配置，支持链式调用，变换情况依据配置的顺序而有所不同\n- 链式调用：当前配置处理完的图像，以流的方式传入下一个配置进行处理，直至结束，`类似Gulp的流处理`\n- 调用结果：不同配置组合的生成图像可能不同，即使相同配置但不同顺序也可能导致生成图像不同\n\n配置|功能|格式(`[]表示可选`)|描述\n-|-|-|-\n`--blur`|模糊|`0.3~1000`|不设置则不生效\n`--extract`|裁剪|`left,top,width,height`|不设置则不生效\n`--flip`|平翻|`true`|不设置则不生效\n`--flop`|对翻|`true`|不设置则不生效\n`--format`|格式|`jpg`或`png`|不设置则使用图像原来的类型\n`--grayscale`|灰度|`true`|不设置则不生效\n`--negate`|负片|`true`|不设置则不生效\n`--normalise`|对比|`true`|不设置则不生效\n`--resize`|尺寸|`width,height[,fit]`|若其中一方为0则自动缩放以匹配另一方\u003cbr\u003e不设置则不生效\n`--rotate`|旋转|`angle[,bgcolor]`|不设置则不生效\n`--sharpen`|锐化|`true`或`[sigama,flat,jagged]`|`true`表示执行快速温和的锐化输出\u003cbr\u003esigama在`0.3~1000`间，其余参数必须`\u003e0`\u003cbr\u003e不设置则不生效\n\n- **fit**：填充\n\t- `cover`：裁剪以适应在指定尺寸中\n\t- `contain`：嵌入在指定尺寸中\n\t- `fill`：忽略宽高比，拉伸以填满在指定尺寸中\n\t- `inside`：保留宽高比，将尺寸调整到尽可能大，同时确保其尺寸小于或等于指定尺寸\n\t- `outside`：保留宽高比，将尺寸调整到尽可能小，同时确保其尺寸大于或等于指定尺寸\n- **bgcolor**：背景色\n\t- `transparent`：透明，需配合`--format png`使用\n\t- `HEX`：16进制色值，可选`#xyz`或`#uvwxyz`\n\t- `RGB`：RGB色值，`rgba(r,g,b)`\n\t- `RGBA`：RGBA色值：`rgba(r,g,b,a)`\n\n\u003e 注意事项\n\n- 配置一定要完整输入且正确，格式为`--opt [val]`，不然会报错导致无法执行\n- 配置参数间相连只能使用英文逗号`,`，不能使用空格\n- 配置详情请参考[sharp-api](https://sharp.pixelplumbing.com/api-constructor)\n\n### 细节\n\n\u003e 压缩图像\n\n- 输出目录为`#compressed-dist#`\n- 图像可任意放置到根目录多层文件夹下，压缩图像后原样输出图像位置到`#compressed-dist#`下\n- 重新压缩图像时，先移除`#compressed-dist#`再生成新的`#compressed-dist#`，注意保存压缩过的图像\n\n\u003e 分组图像\n\n- 输出目录为`#grouped-dist#`\n- 图像可任意放置到根目录多层文件夹下，分组图像后按照分组依据输出图像位置到`#grouped-dist#`下\n- 重新分组图像时，先移除`#grouped-dist#`再生成新的`#grouped-dist#`，注意保存分组过的图像\n\n\u003e 标记图像\n\n- 输出目录为`#marked-dist#`\n- 图像可任意放置到根目录多层文件夹下，标记图像后原样输出图像位置到`#marked-dist#`下\n- 重新标记图像时，先移除`#marked-dist#`再生成新的`#marked-dist#`，注意保存标记过的图像\n\n\u003e 变换图像\n\n- 输出目录为`#transformed-dist#`\n- 图像可任意放置到根目录多层文件夹下，变换图像后原样输出图像位置到`#transformed-dist#`下\n- 重新变换图像时，先移除`#transformed-dist#`再生成新的`#transformed-dist#`，注意保存变换过的图像\n\n### 示例\n\n所有命令作用一次以下文件夹的图像\n\n![原始图像](https://static.yangzw.vip/npm/img-master/原始图像.png)\n\n\u003e 压缩图像\n\n`img-master c`\n\n![压缩图像命令](https://static.yangzw.vip/npm/img-master/压缩图像命令.png)\n\n![压缩图像](https://static.yangzw.vip/npm/img-master/压缩图像.png)\n\n\u003e 分组图像\n\n`img-master g`\n\n![分组图像命令](https://static.yangzw.vip/npm/img-master/分组图像命令.png)\n\n![分组图像](https://static.yangzw.vip/npm/img-master/分组图像.png)\n\n\u003e 标记图像\n\n`img-master m`\n\n![标记图像命令](https://static.yangzw.vip/npm/img-master/标记图像命令.png)\n\n![标记图像](https://static.yangzw.vip/npm/img-master/标记图像.png)\n\n\u003e 变换图像\n\n`img-master t --resize 300,0 --extract 50,50,100,100 --rotate 200,#3c9 --blur 5 --format png`\n\n![变换图像命令](https://static.yangzw.vip/npm/img-master/变换图像命令.png)\n\n![变换图像](https://static.yangzw.vip/npm/img-master/变换图像.png)\n\n```txt\n相同配置但不同顺序也可能导致生成图像不同\n```\n\n### 版权\n\nMIT © [Joway Young](https://github.com/JowayYoung)\n\n### 后记\n\n若觉得`img-master`对你有帮助，可在[Issue](https://github.com/JowayYoung/img-master/issues)上`提出你的宝贵建议`，笔者会认真阅读并整合你的建议。喜欢`img-master`的请给一个[Star](https://github.com/JowayYoung/img-master)，或[Fork](https://github.com/JowayYoung/img-master)本项目到自己的`Github`上，根据自身需求定制功能。\n\n**关注公众号`IQ前端`，一个专注于CSS/JS开发技巧的前端公众号，更多前端小干货等着你喔**\n\n![](https://static.yangzw.vip/frontend/account/IQ前端公众号.jpg)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjowayyoung%2Fimg-master","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjowayyoung%2Fimg-master","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjowayyoung%2Fimg-master/lists"}