Optimize and compress images for web use. Reduces file sizes of JPEG, PNG, GIF images using lossy/lossless compression. Can resize images to maximum dimensions, convert to WebP format, and process entire directories recursively. Use when images are too large for web, need compression, or need format conversion.
Compress and optimize images for web delivery, similar to Squoosh.
# Ensure dependencies are installed
scripts/install-deps.sh
# Optimize images
scripts/imgopt.sh [OPTIONS] <files or directories>
scripts/imgopt.sh photo.jpg
scripts/imgopt.sh images/
scripts/imgopt.sh -q 80 -w 1920 images/
scripts/imgopt.sh --webp images/
scripts/imgopt.sh -r --keep --webp ./website/images/
scripts/imgopt.sh -o optimized/ *.jpg *.png
scripts/imgopt.sh -n -r images/
| Option | Description | Default |
|---|---|---|
-q, --quality N | Quality level 1-100 | 80 |
-w, --max-width N | Maximum width in pixels | unlimited |
-h, --max-height N | Maximum height in pixels | unlimited |
-o, --output DIR | Output directory | in-place |
--webp | Also create WebP versions | off |
--keep | Keep originals (save as .opt.ext) | off |
-r, --recursive | Process directories recursively | off |
-n, --dry-run | Show what would be done | off |
-v, --verbose | Show detailed progress | off |
| Use Case | Command |
|---|---|
| Blog images | -q 80 -w 1200 --webp |
| Hero/banner images | -q 85 -w 1920 --webp |
| Thumbnails | -q 75 -w 400 |
| E-commerce products | -q 85 -w 1000 --webp |
| Maximum compression | -q 60 -w 1920 --webp |
--keep or -o output/ until you're happy with resultsSee references/REFERENCE.md for detailed technical information.