A CLI tool to compress images to fit under a target size in KB by adjusting quality and downscaling if needed.
cargo install sizifysizify [OPTIONS] <input> <output>--target-kb <TARGET_KB>: Target size in KB (upper bound)--format <FORMAT>: Output format: jpeg, webp, or png [default: webp]--max-width <MAX_WIDTH>: Optional max width--max-height <MAX_HEIGHT>: Optional max height--min-quality <MIN_QUALITY>: Min quality (1..=100) [default: 30]--max-quality <MAX_QUALITY>: Max quality (1..=100) [default: 95]--max-downscale-rounds <MAX_DOWNSCALE_ROUNDS>: How many downscale rounds to attempt [default: 10]--png-compression-level <PNG_COMPRESSION_LEVEL>: PNG compression level (0-9, higher = slower but smaller) [default: 6]--help: Print help
Compress an image to under 100 KB as WebP:
sizify input.jpg output.webp --target-kb 100Compress with max dimensions and PNG format:
sizify input.png output.png --target-kb 50 --format png --max-width 800 --max-height 600 --png-compression-level 9- For JPEG and WebP: Uses binary search on quality to find the highest quality that fits the target size. If min quality still exceeds the target, downscales the image by 10% and retries. Pre-downscaling is applied for very large images.
- For PNG: No quality search; encodes at the specified compression level. If too large, downscales by 10% and retries.
- JPEG converts to RGB (transparent pixels become black).
- WebP preserves alpha if present.
- PNG preserves alpha if present.
MIT License - see LICENSE file.