baoyu-compress-image
jimliu/baoyu-skills
Compress images to WebP or PNG with automatic tool selection and quality control.
What is baoyu-compress-image?
Compresses images using the best available system tool (sips, cwebp, ImageMagick, or Sharp). Use when you need to reduce image file size, convert to WebP, or optimize images for web delivery.
- Automatically selects the best compression tool available on the system
- Compresses single files or entire directories recursively
- Supports WebP (default), PNG, and JPEG output formats
- Configurable quality levels (0-100) to balance file size and visual quality
- Optionally preserves original files while creating compressed versions
- Outputs JSON results for programmatic integration
How to install baoyu-compress-image
npx skills add https://github.com/jimliu/baoyu-skills --skill baoyu-compress-image- bun or npx installed on your system
How to use baoyu-compress-image
- 1.Run the compression command with an input file or directory path
- 2.Optionally specify output format with --format (webp, png, jpeg)
- 3.Set quality level with --quality (0-100; default 80)
- 4.Use --recursive to process subdirectories
- 5.Use --keep to preserve the original file alongside the compressed version
- 6.Use --json flag if you need machine-readable output
Use cases
- Reduce image file sizes before uploading to web servers or CDNs
- Convert PNG or JPEG images to modern WebP format for better compression
- Batch compress all images in a project directory with recursive processing
- Optimize images for email or messaging while maintaining quality
- Automate image compression in build pipelines with JSON output
- Web developers optimizing assets for production
- Content creators managing large image libraries
- DevOps engineers automating asset pipelines
- Anyone needing quick, lossless image compression
baoyu-compress-image FAQ
WebP, which offers the best compression ratio. You can change this with --format png or --format jpeg.
Yes, by default it replaces the original. Use --keep to preserve both the original and compressed versions.
Yes, pass a directory path and use --recursive to process all images in subdirectories.
Create an EXTEND.md file in one of the preference paths (.baoyu-skills/baoyu-compress-image/EXTEND.md, XDG config, or home directory) to set default format, quality, and keep-original preference.
The tool automatically falls back to the next available option (sips → cwebp → ImageMagick → Sharp), so it works even with minimal dependencies.
Full instructions (SKILL.md)
Source of truth, from jimliu/baoyu-skills.
name: baoyu-compress-image description: Compresses images to WebP (default) or PNG with automatic tool selection. Use when user asks to "compress image", "optimize image", "convert to webp", or reduce image file size. version: 1.56.1 metadata: openclaw: homepage: https://github.com/JimLiu/baoyu-skills#baoyu-compress-image requires: anyBins: - bun - npx
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.
Related skills
More from jimliu/baoyu-skills and the wider catalog.
baoyu-post-to-wechat
Post articles and image-text content to WeChat Official Accounts via API or browser automation.
baoyu-image-gen
Multi-provider AI image generation with text-to-image, reference images, batch processing, and aspect ratio control.
baoyu-markdown-to-html
Convert Markdown to styled HTML with WeChat-compatible themes, code highlighting, math, and Mermaid diagrams.
baoyu-infographic
Generate professional infographics with 21 layouts and 22 styles—analyze content and produce publication-ready visuals.
baoyu-cover-image
Generate customizable article cover images with 5 dimensions, 11 color palettes, and 7 rendering styles.
baoyu-article-illustrator
Analyze articles and generate illustrated images with consistent Type × Style × Palette approach.