Skip to content

Batch processing

imgsqz accepts multiple inputs in a single command. Every flag you set applies to all of them, and you get a per-file size report.

List them explicitly:

Terminal window
imgsqz a.png b.png c.png -f webp -q 75

Your shell expands globs before imgsqz runs, so any glob your shell supports works:

Terminal window
# Every PNG in the current directory
imgsqz *.png -f webp
# Every JPG, recursively (zsh / bash with globstar)
imgsqz **/*.jpg -f avif -q 50

Enable recursive globs first:

Terminal window
shopt -s globstar
imgsqz **/*.png -f webp -q 75
  • Each input is processed in order, one at a time.
  • Each success prints its three-line report (unless --quiet).
  • Each failure prints ✗ <file>: <reason> to stderr and continues.
  • If any file failed, imgsqz exits with code 1 — handy for CI.
a.png
→ a_20260611_132517.webp
1.20 MB → 180.04 KB (↓ 85.3%)
b.png
→ b_20260611_132517.webp
900.00 KB → 120.50 KB (↓ 86.6%)
✗ broken.png: Input file not found: /path/broken.png

For large folders or CI logs, silence the per-file output:

Terminal window
imgsqz *.jpg -f webp -q 75 --quiet

Errors still print, and the exit code still reflects failures.

When you need per-file output paths or a separate output directory, loop:

Terminal window
mkdir -p optimized
for f in src/*.png; do
name=$(basename "$f" .png)
imgsqz "$f" -f webp -q 75 -o "optimized/$name.webp"
done

imgsqz processes its own inputs sequentially. To use all your cores, fan out with xargs or GNU parallel, one file per process:

Terminal window
# 4 files at a time with xargs
ls *.png | xargs -P 4 -I{} imgsqz {} -f webp -q 75 --quiet
# GNU parallel
parallel imgsqz {} -f webp -q 75 --quiet ::: *.png

Next: Output paths & naming.