imgconv

A CLI tool that converts JPG and PNG images to WebP or AVIF — with an optional optimize mode that uses perceptual quality scoring to find the smallest file size your eyes can’t tell apart from the original.

imgconv is a bash script that batch-converts JPG and PNG images to modern formats — WebP or AVIF — from the command line. Point it at a folder, pick a format, and it handles the rest.

The real trick is optimize mode. Instead of guessing at a quality setting, imgconv uses ssimulacra2 — a perceptual image quality metric — to binary-search for the lowest quality level that still meets a visual fidelity threshold. You get the smallest possible file that still looks indistinguishable from the original.

How it works

In fixed quality mode, imgconv encodes each image at your specified quality (default: 80) — straightforward batch conversion.

In optimize mode, for each image it:

  1. Converts the source to a reference PNG
  2. Encodes a test version at the midpoint quality
  3. Decodes it back and scores it against the original using ssimulacra2
  4. Binary-searches up or down — lower if the score passes the threshold, higher if it doesn’t
  5. Writes the final file at the optimal quality found

The result: dramatically smaller files with no perceptible quality loss. Every image gets its own optimal quality rather than a one-size-fits-all setting.

Usage

# Basic conversion
imgconv ./photos --webp
imgconv ./photos --avif

# Set quality
imgconv ./photos --avif -q 70

# Recursive + delete originals
imgconv ./photos --webp -r --delete

# Optimize mode — auto-find best quality per image
imgconv ./photos --webp --optimize

# Optimize with custom threshold (higher = stricter fidelity)
imgconv ./photos --avif --optimize --threshold 70

Options

FlagDescription
--webp / --avifOutput format (pick one, required)
-r, --recursiveProcess subdirectories
-q, --quality <0-100>Compression quality (default: 80)
--optimizeBinary-search for lowest quality meeting perceptual threshold
--threshold <0-100>Minimum ssimulacra2 score for optimize mode (default: 60)
--deleteDelete originals after successful conversion

Dependencies

# Core (one or both depending on format)
brew install webp      # cwebp + dwebp
brew install libavif   # avifenc + avifdec

# For optimize mode
brew install ssimulacra2

Why we built it

Most image optimization tools either give you a fixed quality dial or a black-box “auto” mode you can’t inspect. We wanted something that used an actual perceptual metric to make compression decisions — and that showed its work. The output tells you the quality it chose, the ssimulacra2 score, and the file size savings for every image.

It’s a single bash script with no framework, no config file, and no build step. Copy it somewhere in your PATH and go.