宝玉压缩图像
- 作者仓库星标 0
- 作者更新于 2026年7月4日 01:22
- 作者仓库 baoyu-skills
- 领域
- 设计与多媒体
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 92 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @JimLiu · v1.56.1 · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 即装即用
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- macOS · Linux · Windows
- 运行环境要求
- Bun
- 检测到的文件与系统行为
-
- 只读
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
# 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
# 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
```
**Output**:
```
image.png → image.webp (245KB → 89KB, 64% reduction)
```
## Extension Support
Custom configurations via EXTEND.md. See **Preferences** section for paths and supported options.
章节与文件索引
按说明文件中的顺序排列。
脚本目录
首选项(EXTEND.md)
选项
示例
扩展支持
文件/命令 -> scripts/ · {baseDir} · ${BUN_X} · bun · npx · npx -y bun · scripts/main.ts · .baoyu-skills/baoyu-compress-image/EXTEND.md
内容校验值 -> 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、上传逻辑接到压缩流程末尾)。