A powerful command-line tool for resizing images by file size and/or dimensions, written in Rust.
- Target File Size: Automatically compress images to stay under a specific file size (in KB)
- Dimension Resizing: Resize images to specific dimensions with optional aspect ratio maintenance
- Batch Processing: Process individual files or entire directories
- Smart Compression: Uses iterative compression and scaling to achieve target sizes
- Multiple Format Support: JPEG, PNG, GIF, BMP, WebP
Resize a single image to under 100KB:
image-resizer -i photo.jpg -s 100Resize all images in a directory to under 500KB:
image-resizer -i /path/to/images -s 500Resize to specific dimensions:
image-resizer -i photo.jpg -d 800x600Combine size and dimension constraints:
image-resizer -i photo.jpg -s 200 -d 1024x768Maintain aspect ratio when resizing:
image-resizer -i photo.jpg -d 800x600 -rSpecify output directory:
image-resizer -i input_dir -s 100 -o output_dir-i, --input <PATH>- Input image file or directory (required)-s, --size <KB>- Target file size in kilobytes-d, --dimensions <WIDTHxHEIGHT>- Target dimensions (e.g., 800x600)-o, --output <DIR>- Output directory (default: creates 'resized' subdirectory)-r, --maintain-ratio- Maintain aspect ratio when resizing-h, --help- Print help information-V, --version- Print version information
- Quality Reduction: First tries to reduce file size by lowering JPEG quality (95% → 20%)
- Image Scaling: If quality reduction isn't enough, starts scaling down the image by 10% increments
- Iterative Process: Continues until the target size is achieved or maximum iterations reached
- Best Fit: Saves the best result that meets the size requirements
- JPEG/JPG - Uses quality-based compression
- PNG - Uses compression level optimization
- GIF, BMP - Basic support
- WebP - Converted to JPEG for compression (native WebP support can be added)
Batch resize photos for web upload (max 2MB):
image-resizer -i vacation_photos/ -s 2048 -o web_ready/Prepare thumbnails (200x200, max 50KB):
image-resizer -i products/ -d 200x200 -s 50 -r -o thumbnails/Process a single large photo for email:
image-resizer -i DSC_0001.jpg -s 500 -d 1920x1080 -rThe tool provides feedback for each processed image:
Found 3 image(s) to process
✓ Processed: photo1.jpg (3456 KB → 98 KB)
→ Compressed with quality 75 to meet size target
✓ Processed: photo2.png (2100 KB → 95 KB)
→ Scaled to 85% with quality 80 to meet size target
✓ Processed: photo3.jpg (5200 KB → 99 KB)
→ Scaled to 70% with quality 85 to meet size target
- PNG Files: PNG compression is less flexible than JPEG. For strict size requirements, consider converting to JPEG
- Quality vs Size: The tool prioritizes meeting size requirements over maintaining quality
- Aspect Ratio: Use
-rflag to prevent image distortion when resizing - Large Reductions: For very large size reductions (e.g., 10MB → 100KB), expect significant quality loss
Consider adding:
- Progress bars for batch processing (using
indicatifcrate) - Better WebP support (using
webpcrate) - Configuration file support
- Parallel processing for faster batch operations
- Custom quality ranges
- EXIF data preservation options