← Back to blog

Published on 2026-03-01 18:37 by Manu Gallego

imgtools.sh

A command-line utility to optimize, resize, and convert images for the web using ImageMagick (v6/v7) and dedicated encoders (mozjpeg, cwebp, avifenc) when available.

Features

Requirements

Better encoders (optional, auto-detected)

When installed, these replace ImageMagick for their respective formats and produce smaller files at equal quality:

EncoderFormatInstall
mozjpegJPEGbrew install mozjpeg
cwebpWebPbrew install webp
avifencAVIFbrew install libavif
fswatch / inotifywait(watch mode)brew install fswatch

Dependency installation

The script includes a command to check and install dependencies:

./imgtools.sh install

It detects and attempts installation via apt, brew, dnf, yum, or apk.

Usage

./imgtools.sh [action] [value] [options]

Actions

Options

Examples

Optimize images at 80% quality:

./imgtools.sh optimize 80

Optimize and also resize/convert to WebP:

./imgtools.sh optimize 85 --resize 1200h --format webp

Resize from src to dist with suffix and verbose output:

./imgtools.sh resize 1200h -i ./src -o ./dist --suffix web -v

Optimize with progressive JPEG using 4 parallel workers:

./imgtools.sh optimize 80 --progressive --jobs 4 -i ./src -o ./dist

Process recursively and overwrite outputs:

./imgtools.sh resize 400v --overwrite --recursive

Watch a directory and convert every new upload to WebP on the fly:

./imgtools.sh optimize 80 --format webp --watch -i ./uploads -o ./dist

Simulate without writing files:

./imgtools.sh optimize 80 --prefix web --format webp --dry-run -v
  1. Run in simulation mode to validate outputs:
    ./imgtools.sh optimize 80 --dry-run -v
    
  2. Run again without --dry-run.
  3. Review the final summary (processed, skipped, errors, and total savings).

Project structure

img_tools/
├── imgtools.sh
└── README.md

Notes

License

This project is licensed under the GNU General Public License v3.0 (GPLv3). See the full license text for details.

View on GitHub

IMG Tools

Written by Manu Gallego

← Back to blog