baoyu-compress-image

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Image Compressor

图片压缩工具

Compresses images using best available tool (sips → cwebp → ImageMagick → Sharp).
使用可用的最佳工具压缩图片(优先级:sips → cwebp → ImageMagick → Sharp)。

Script Directory

脚本目录

Scripts in
scripts/
subdirectory. Replace
${SKILL_DIR}
with this SKILL.md's directory path.
ScriptPurpose
scripts/main.ts
Image compression CLI
脚本位于
scripts/
子目录中。将
${SKILL_DIR}
替换为此SKILL.md所在的目录路径。
脚本用途
scripts/main.ts
图片压缩CLI工具

Preferences (EXTEND.md)

偏好设置(EXTEND.md)

Use Bash to check EXTEND.md existence (priority order):
bash
undefined
使用Bash检查EXTEND.md是否存在(优先级顺序):
bash
undefined

Check project-level first

先检查项目级路径

test -f .baoyu-skills/baoyu-compress-image/EXTEND.md && echo "project"
test -f .baoyu-skills/baoyu-compress-image/EXTEND.md && echo "project"

Then user-level (cross-platform: $HOME works on macOS/Linux/WSL)

再检查用户级路径(跨平台:$HOME 在 macOS/Linux/WSL 均适用)

test -f "$HOME/.baoyu-skills/baoyu-compress-image/EXTEND.md" && echo "user"

┌────────────────────────────────────────────────────────┬───────────────────┐
│                          Path                          │     Location      │
├────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-compress-image/EXTEND.md           │ Project directory │
├────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-compress-image/EXTEND.md     │ User home         │
└────────────────────────────────────────────────────────┴───────────────────┘

┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│  Result   │                                  Action                                   │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Found     │ Read, parse, apply settings                                               │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Not found │ Use defaults                                                              │
└───────────┴───────────────────────────────────────────────────────────────────────────┘

**EXTEND.md Supports**: Default format | Default quality | Keep original preference
test -f "$HOME/.baoyu-skills/baoyu-compress-image/EXTEND.md" && echo "user"

┌────────────────────────────────────────────────────────┬───────────────────┐
│                          路径                          │     位置      │
├────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-compress-image/EXTEND.md           │ 项目目录 │
├────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-compress-image/EXTEND.md     │ 用户主目录         │
└────────────────────────────────────────────────────────┴───────────────────┘

┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│  结果   │                                  操作                                   │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 找到     │ 读取、解析、应用设置                                               │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 未找到 │ 使用默认设置                                                              │
└───────────┴───────────────────────────────────────────────────────────────────────────┘

**EXTEND.md 支持**:默认格式 | 默认质量 | 是否保留原文件偏好

Usage

使用方法

bash
npx -y bun ${SKILL_DIR}/scripts/main.ts <input> [options]
bash
npx -y bun ${SKILL_DIR}/scripts/main.ts <input> [options]

Options

选项

OptionShortDescriptionDefault
<input>
File or directoryRequired
--output
-o
Output pathSame path, new ext
--format
-f
webp, png, jpegwebp
--quality
-q
Quality 0-10080
--keep
-k
Keep originalfalse
--recursive
-r
Process subdirsfalse
--json
JSON outputfalse
选项简写描述默认值
<input>
文件或目录必填
--output
-o
输出路径原路径,新扩展名
--format
-f
webp, png, jpegwebp
--quality
-q
质量 0-10080
--keep
-k
保留原文件false
--recursive
-r
处理子目录false
--json
JSON格式输出false

Examples

示例

bash
undefined
bash
undefined

Single file → WebP (replaces original)

单个文件 → WebP(替换原文件)

npx -y bun ${SKILL_DIR}/scripts/main.ts image.png
npx -y bun ${SKILL_DIR}/scripts/main.ts image.png

Keep PNG format

保留PNG格式

npx -y bun ${SKILL_DIR}/scripts/main.ts image.png -f png --keep
npx -y bun ${SKILL_DIR}/scripts/main.ts image.png -f png --keep

Directory recursive

递归处理目录

npx -y bun ${SKILL_DIR}/scripts/main.ts ./images/ -r -q 75
npx -y bun ${SKILL_DIR}/scripts/main.ts ./images/ -r -q 75

JSON output

JSON格式输出

npx -y bun ${SKILL_DIR}/scripts/main.ts image.png --json

**Output**:
image.png → image.webp (245KB → 89KB, 64% reduction)
undefined
npx -y bun ${SKILL_DIR}/scripts/main.ts image.png --json

**输出示例**:
image.png → image.webp (245KB → 89KB, 64% reduction)
undefined

Extension Support

扩展支持

Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
通过EXTEND.md进行自定义配置。有关路径和支持的选项,请查看偏好设置部分。