| name | image-compress |
| description | Compress images to a target file size using macOS sips. No dependencies required. |
Image Compress Skill
Compress images to a target file size using macOS built-in sips. Works with PNG, JPEG, HEIC, TIFF, and more.
Usage
~/dev/pi-skills/image-compress/compress.sh <input> [output] [options]
Options:
--target MB - Target size in MB (default: 5)
--width WIDTH - Scale to width (maintains aspect ratio)
--format FORMAT - Convert to format: jpeg, png, heic, tiff (default: keep original)
--quality 0-100 - JPEG/HEIC quality (default: 85)
If no output is specified, creates <input>_compressed.<ext> in the same directory.
Examples
compress.sh photo.png
compress.sh photo.png out.png --target 2
compress.sh photo.png out.jpg --format jpeg
compress.sh photo.png out.png --width 2000
compress.sh photo.png out.jpg --format jpeg --quality 95
How it works
- Gets current dimensions and file size
- Strips ICC color profile (avoids sips warnings)
- If format conversion requested, converts first
- Calculates required scale factor to hit target size
- Iteratively resizes until under target (binary search approach)
- Reports final dimensions and size
Note: Uses decimal MB (1 MB = 1,000,000 bytes) to match Finder.