baoyu-compress-image
- 作者仓库星标 0
- 作者更新于 2026年7月4日 09:22
- 作者仓库 baoyu-skills
图像压缩器
使用最佳可用工具(sips → cwebp → ImageMagick → Sharp)压缩图像。
脚本目录
脚本位于 scripts/ 子目录中。{baseDir} = 此 SKILL.md 的目录路径。解析 ${BUN_X} 运行时:如果安装了 bun → bun;如果 npx 可用 → npx -y bun;否则建议安装 bun。将 {baseDir} 和 ${BUN_X} 替换为实际值。
| 脚本 | 用途 |
|---|---|
scripts/main.ts |
图像压缩 CLI |
首选项 (EXTEND.md)
按优先级顺序检查 EXTEND.md — 找到的第一个生效:
| 优先级 | 路径 | 范围 |
|---|---|---|
| 1 | .baoyu-skills/baoyu-compress-image/EXTEND.md |
项目 |
| 2 | ${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-compress-image/EXTEND.md |
XDG |
| 3 | $HOME/.baoyu-skills/baoyu-compress-image/EXTEND.md |
用户主目录 |
如果未找到,则使用默认值。
EXTEND.md 支持:默认格式、默认质量、保留原始文件首选项。
用法
${BUN_X} {baseDir}/scripts/main.ts <input> [options]
选项
| 选项 | 缩写 | 描述 | 默认值 |
|---|---|---|---|
<input> |
文件或目录 | 必填 | |
--output |
-o |
输出路径 | 相同路径,新扩展名 |
--format |
-f |
webp, png, jpeg | webp |
--quality |
-q |
质量 0-100 | 80 |
--keep |
-k |
保留原始文件 | false |
--recursive |
-r |
处理子目录 | false |
--json |
JSON 输出 | false |
示例
# 单个文件 → WebP(替换原始文件)
${BUN_X} {baseDir}/scripts/main.ts image.png
# 保留 PNG 格式
${BUN_X} {baseDir}/scripts/main.ts image.png -f png --keep
# 目录递归
${BUN_X} {baseDir}/scripts/main.ts ./images/ -r -q 75
# JSON 输出
${BUN_X} {baseDir}/scripts/main.ts image.png --json
输出:
image.png → image.webp (245KB → 89KB, 64% reduction)
扩展支持
通过 EXTEND.md 进行自定义配置。请参阅「首选项」部分了解路径和支持的选项。
Image Compressor
Compresses images using best available tool (sips → cwebp → ImageMagick → Sharp).
Script Directory
Scripts in scripts/ subdirectory. {baseDir} = this SKILL.md's directory path. Resolve ${BUN_X} runtime: if bun installed → bun; if npx available → npx -y bun; else suggest installing bun. Replace {baseDir} and ${BUN_X} with actual values.
| Script | Purpose |
|---|---|
scripts/main.ts |
Image compression CLI |
Preferences (EXTEND.md)
Check EXTEND.md in priority order — the first one found wins:
| Priority | Path | Scope |
|---|---|---|
| 1 | .baoyu-skills/baoyu-compress-image/EXTEND.md |
Project |
| 2 | ${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-compress-image/EXTEND.md |
XDG |
| 3 | $HOME/.baoyu-skills/baoyu-compress-image/EXTEND.md |
User home |
If none found, use defaults.
EXTEND.md supports: Default format, default quality, keep-original preference.
Usage
${BUN_X} {baseDir}/scripts/main.ts <input> [options]
Options
| Option | Short | Description | Default |
|---|---|---|---|
<input> |
File or directory | Required | |
--output |
-o |
Output path | Same path, new ext |
--format |
-f |
webp, png, jpeg | webp |
--quality |
-q |
Quality 0-100 | 80 |
--keep |
-k |
Keep original | false |
--recursive |
-r |
Process subdirs | false |
--json |
JSON output | false |
Examples
# Single file → WebP (replaces original)
${BUN_X} {baseDir}/scripts/main.ts image.png
# Keep PNG format
${BUN_X} {baseDir}/scripts/main.ts image.png -f png --keep
# Directory recursive
${BUN_X} {baseDir}/scripts/main.ts ./images/ -r -q 75
# JSON output
${BUN_X} {baseDir}/scripts/main.ts image.png --json
Output:
image.png → image.webp (245KB → 89KB, 64% reduction)
Extension Support
Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
- 流狐分类
- 设计与多媒体
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 92 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @JimLiu · v1.56.1 · 未声明 license
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 即装即用
- 是否需要外部 API Key
- 未发现要求
- 检测到的系统要求
- macOS · Linux · Windows
- 底层运行要求
- Bun
- 检测到的文件与系统行为
-
- 只读
- 检测到的网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
作者没有在当前 SKILL.md 中定义固定输出样例。 Scripts in scripts/ subdirectory. {baseDir} = this SKILL.md's directory path. Resolve ${BUNX} runtime: if bun installed → bun; if npx available → npx -y bun; else suggest installing bun. Replace {baseDir} and ${BUNX} with actual values.
Check EXTEND.md in priority order — the first one found wins: Priority · Path · Scope 1 · .baoyu-skills/baoyu-compress-image/EXTEND.md · Project
Usage
Option · Short · Description · Default <input> · File or directory · Required --output · -o · Output path · Same path, new ext
Output:
Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
# Image Compressor
Compresses images using best available tool (sips → cwebp → ImageMagick → Sharp).
## Script Directory
Scripts in `scripts/` subdirectory. `{baseDir}` = this SKILL.md's directory path. Resolve `${BUN_X}` runtime: if `bun` installed → `bun`; if `npx` available → `npx -y bun`; else suggest installing bun. Replace `{baseDir}` and `${BUN_X}` with actual values.
| Script | Purpose |
|--------|---------|
| `scripts/main.ts` | Image compression CLI |
## Preferences (EXTEND.md)
Check EXTEND.md in priority order — the first one found wins:
| Priority | Path | Scope |
|----------|------|-------|
| 1 | `.baoyu-skills/baoyu-compress-image/EXTEND.md` | Project |
| 2 | `${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-compress-image/EXTEND.md` | XDG |
| 3 | `$HOME/.baoyu-skills/baoyu-compress-image/EXTEND.md` | User home |
If none found, use defaults.
**EXTEND.md supports**: Default format, default quality, keep-original preference.
## Usage
```bash
${BUN_X} {baseDir}/scripts/main.ts <input> [options]
```
## Options
| Option | Short | Description | Default |
|--------|-------|-------------|---------|
| `<input>` | | File or directory | Required |
| `--output` | `-o` | Output path | Same path, new ext |
| `--format` | `-f` | webp, png, jpeg | webp |
| `--quality` | `-q` | Quality 0-100 | 80 |
| `--keep` | `-k` | Keep original | false |
| `--recursive` | `-r` | Process subdirs | false |
| `--json` | | JSON output | false |
## Examples
```bash
# Single file → WebP (replaces original)
${BUN_X} {baseDir}/scripts/main.ts image.png
# Keep PNG format
${BUN_X} {baseDir}/scripts/main.ts image.png -f png --keep
# Directory recursive
${BUN_X} {baseDir}/scripts/main.ts ./images/ -r -q 75
# JSON output
${BUN_X} {baseDir}/scripts/main.ts image.png --json
```
… 作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> Script Directory → Preferences (EXTEND.md) → Usage → Options → Examples → Extension Support
要点 -> EXTEND.md supports · Output · Preferences · Compresses images using best available tool (sips → cwebp → ImageMagick → Sharp). · Scripts in scripts/ subdirectory. · If none found, use defaults. · EXTEND.md supports: Default format, default quality, keep-original preference. · Custom configurations via EXTEND.md.
文件/命令 -> scripts/ · {baseDir} · ${BUNX} · bun · npx · npx -y bun · scripts/main.ts · .baoyu-skills/baoyu-compress-image/EXTEND.md
内容 SHA-256 -> 47d92af0d850
baoyu-compress-image 解决的是「图片体积大、上传慢、不同平台尺寸限制不一样」的工程化痛点——它不重新发明压缩算法,只是把现有最佳工具自动选好、参数调好。
设计思路
作者的策略叫「best available tool」:不强求装某个特定库,而是按优先级探测系统里已有的工具:sips(macOS 自带)→ cwebp(Google WebP 官方)→ ImageMagick → Sharp(Node 库),哪个先找到用哪个。这意味着一台干净的 mac 可以零依赖直接用,复杂环境也能落地。默认输出格式是 WebP,体积压缩比最好;不接受 WebP 的平台可降级到 PNG。
工作流
脚本目录:
{baseDir}/scripts/。运行时它会:① 解析{baseDir}和${BUN_X}占位符(bun 优先,其次 npx -y bun,都没有就提示装 bun);② 探测系统里第一个可用的压缩工具;③ 按你给的参数(质量、尺寸、批量目录)执行;④ 输出对照表(原大小 → 压后大小 → 比例)。适合谁
关键参数
.webp后缀,原图不丢注意
透明背景、需要逐像素对比的场景,不要用有损 WebP——选 PNG 或调到无损 WebP(quality=100)。EXTEND.md 提供进一步扩展点(你可以把自家 CDN、上传逻辑接到压缩流程末尾)。