Image compression CLI with lossless and lossy options
npm install qasaiA powerful image compression CLI with multiple engine support, lossless/lossy options, and both interactive and non-interactive modes.
š Full Specification
- Multiple compression engines - Choose the best tool for each format
- Lossless & lossy compression - Optimize without quality loss or maximize savings
- Batch processing - Compress entire directories recursively
- Format conversion - Convert between JPG, PNG, WebP, AVIF
- Resize options - Scale by dimensions, percentage, or max width/height
- Interactive & CLI modes - Guided prompts or scriptable commands
- Parallel processing - Process multiple files concurrently
- Dry run mode - Preview changes without compressing
- JSON output - Machine-readable output for automation
``bash`
npm install -g qasaior
npx qasai
Install as an AI agent skill:
`bash`
npx skills ahmadawais/qasai
`bash`
qasai
Launches a guided interface to configure compression options.
`bashCompress current directory (outputs to ./qasai folder)
qasai .
CLI Options
| Short | Long | Description | Default |
|-------|------|-------------|---------|
|
-o | --output | Output directory | qasai/ folder |
| -i | --in-place | Overwrite original files | false |
| -q | --quality | Quality 1-100 | 80 |
| -l | --lossless | Lossless compression | false |
| -s | --resize | Resize (e.g., 800x600, 50%) | - |
| -w | --max-width | Max width (keeps aspect ratio) | - |
| -H | --max-height | Max height (keeps aspect ratio) | - |
| -f | --format | Convert to format (jpg, png, webp, avif) | - |
| -r | --recursive | Process subdirectories | false |
| -m | --keep-metadata | Preserve EXIF data | false |
| | --no-progressive | Disable progressive JPEGs | false |
| -e | --effort | Compression effort 1-10 | 6 |
| -j | --jpeg-engine | mozjpeg, jpegtran, sharp | mozjpeg |
| -p | --png-engine | pngquant, optipng, sharp | pngquant |
| -g | --gif-engine | gifsicle, sharp | gifsicle |
| | --png-quality | PNG quality range | 65-80 |
| -c | --colors | Max colors for PNG/GIF | 256 |
| -D | --dry-run | Preview without compressing | false |
| -Q | --quiet | Silent mode (only errors) | false |
| | --json | Output results as JSON | false |
| -S | --skip-existing | Skip existing output files | false |
| -P | --parallel | Parallel processing workers | 4 |
| -B | --backup | Backup before in-place compression | false |
| -v | --version | Show version | - |
| -h | --help | Display help | - |Compression Engines
QASAI uses the best compression engine for each format by default:
$3
| Engine | Type | Description | Default |
|--------|------|-------------|---------|
| mozjpeg | Lossy | Best compression ratio, 5-10% smaller than libjpeg | ā
|
| jpegtran | Lossless | Optimizes Huffman tables, no recompression | |
| sharp | Lossy | Fast, uses libvips with MozJPEG | |
`bash
Use MozJPEG (default, best compression)
qasai ./images -j mozjpegUse jpegtran (pure lossless, no quality loss at all)
qasai ./images -j jpegtranUse Sharp (fastest)
qasai ./images -j sharp
`$3
| Engine | Type | Description | Default |
|--------|------|-------------|---------|
| pngquant | Lossy | Best compression, reduces to 256 colors | ā
|
| optipng | Lossless | Optimizes without color reduction | |
| sharp | Both | Fast, good compression | |
`bash
Use pngquant (default, best compression)
qasai ./images -p pngquantUse OptiPNG (lossless)
qasai ./images -p optipngLimit colors (2-256)
qasai ./images -c 128
`$3
| Engine | Type | Description | Default |
|--------|------|-------------|---------|
| gifsicle | Both | Best for animated GIFs, preserves animation | ā
|
| sharp | Basic | Fast, basic optimization | |
$3
SVGs are always optimized with SVGO:
- Removes metadata, comments, hidden elements
- Optimizes path data
- Multipass optimization
$3
Handled by Sharp with libvips:
- Native lossless mode support
- Effort levels 1-10 for compression/speed tradeoff
Examples
$3
`bash
Compress with defaults (creates qasai folder)
qasai ./photosHigh quality compression
qasai ./photos -q 90Maximum compression (lower quality)
qasai ./photos -q 60
`$3
`bash
Lossless JPEG (jpegtran)
qasai ./photos -j jpegtranLossless PNG (optipng)
qasai ./photos -p optipngLossless flag (uses lossless mode for WebP/AVIF)
qasai ./photos -l
`$3
`bash
Max width 1920px (maintains aspect ratio)
qasai ./photos -w 1920Max height 1080px
qasai ./photos -H 1080Specific dimensions
qasai ./photos -s 800x600Scale to 50%
qasai ./photos -s 50%
`$3
`bash
Convert all to WebP
qasai ./photos -f webpConvert to AVIF (best compression)
qasai ./photos -f avifConvert to JPEG
qasai ./photos -f jpg
`$3
`bash
Recursive with all options
qasai ./website -r -q 80 -w 1920 -j mozjpeg -p pngquant -o ./optimized
`$3
`bash
Dry run (preview without compressing)
qasai ./images -DQuiet mode for scripting
qasai ./images -Q -q 80JSON output for automation
qasai ./images --jsonSkip existing files
qasai ./images -S -o ./outParallel processing (8 workers)
qasai ./images -P 8 -rIn-place with backup
qasai ./images -i -B
`Supported Formats
| Format | Input | Output | Engines |
|--------|-------|--------|---------|
| JPEG | ā
| ā
| mozjpeg, jpegtran, sharp |
| PNG | ā
| ā
| pngquant, optipng, sharp |
| WebP | ā
| ā
| sharp |
| AVIF | ā
| ā
| sharp |
| GIF | ā
| ā
| gifsicle, sharp |
| SVG | ā
| ā
| svgo |
| TIFF | ā
| ā
| sharp |
Recommended Settings
$3
`bash
qasai ./images -q 80 -w 1920 -r
`$3
`bash
qasai ./images -q 60 -j mozjpeg -p pngquant
`$3
`bash
qasai ./images -j jpegtran -p optipng -l
`$3
`bash
qasai ./images -f webp -q 80
or for best compression:
qasai ./images -f avif -q 70
``1. JPEG: MozJPEG provides 5-10% better compression than standard libjpeg. jpegtran offers pure lossless optimization by reorganizing data without recompression.
2. PNG: pngquant reduces colors to 256 (lossy but visually identical), achieving 60-80% size reduction. OptiPNG provides lossless optimization.
3. GIF: Gifsicle optimizes animated GIFs while preserving all frames and timing.
4. SVG: SVGO removes unnecessary data, optimizes paths, and minifies the XML.
5. WebP/AVIF: Sharp uses libvips for native encoding with quality and effort controls.
Apache 2.0 by Ahmad Awais