A fast CLI tool for batch compressing and converting images to WebP format.
- ✅ Converts JPEG, JPG, and PNG images to WebP
- ✅ Automatic compression and resizing
- ✅ Interactive and command-line modes
- ✅ Configurable quality and dimensions
- ✅ Custom output directory support
- ✅ Progress tracking during compression
- ✅ Comprehensive input validation
npm install -g compressor-cligit clone <repo-url>
cd compressor-cli
npm install
npm run build
npm linkcomp-cli <input-directory> [options]Example:
# Basic usage (default: quality 80, width 1080px, output ./output)
comp-cli ./images
# Custom quality and width
comp-cli ./images -q 90 -w 1920
# Custom output directory
comp-cli ./images -o ./compressed
# All options combined
comp-cli ./images -q 70 -w 800 -o ./dist/imagesIf no arguments are provided, comp-cli starts in interactive mode:
comp-cli
# Follow the prompts to enter your source directoryRight now interactive mode only accepts the path directory to the images to be compressed. All other values fallback to default values. See below.
| Flag | Long Form | Description | Default |
|---|---|---|---|
-q |
--quality |
WebP quality (1-100) | 80 |
-w |
--width |
Target width in pixels | 1080 |
-o |
--output |
Output directory path | ./output |
-h |
--help |
Show help information | - |
-v |
--version |
Show current version | - |
Input: .jpeg, .jpg, .png
Output: .webp
- Validates the input directory exists and contains supported images
- Creates the output directory if it doesn't exist
- Compresses each image to WebP format with specified settings
- Resizes images to the target width (maintains aspect ratio)
- Reports progress and completion status
comp-cli ./photos -w 400 -q 70 -o ./thumbnailscomp-cli ./originals -q 95 -w 2560 -o ./webpcomp-cli ./imagesnpm run dev # Run with tsx (development)
npm run build # Compile TypeScript
npm run link # Build and link globally
npm run unlink # Unlink from globalsrc/
├── index.ts # Main entry point
├── validation.ts # Input validation and argument parsing
├── logger.ts # Logging utilities
└── info.ts # Help text and constants
tests/
└── compression.tests.ts # Vitest testing
- Add support for additional formats (GIF, BMP, TIFF)
- Implement percentage-based resizing
- Add concurrency control for large batches
- Support for multiple output formats
- Dry-run mode to preview operations
- Configuration file support
- Unit tests
ISC
Dielan Garve