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.
Multiple files
Section titled “Multiple files”List them explicitly:
imgsqz a.png b.png c.png -f webp -q 75Your shell expands globs before imgsqz runs, so any glob your shell supports works:
# Every PNG in the current directoryimgsqz *.png -f webp
# Every JPG, recursively (zsh / bash with globstar)imgsqz **/*.jpg -f avif -q 50Enable recursive globs first:
shopt -s globstarimgsqz **/*.png -f webp -q 75Recursive globs work out of the box:
imgsqz **/*.png -f webp -q 75imgsqz **.png -f webp -q 75PowerShell doesn’t expand globs the same way — pipe paths instead:
Get-ChildItem -Recurse -Filter *.png | ForEach-Object { imgsqz $_.FullName -f webp -q 75 }How batches behave
Section titled “How batches behave”- 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.pngQuiet batches
Section titled “Quiet batches”For large folders or CI logs, silence the per-file output:
imgsqz *.jpg -f webp -q 75 --quietErrors still print, and the exit code still reflects failures.
Shell loops for full control
Section titled “Shell loops for full control”When you need per-file output paths or a separate output directory, loop:
mkdir -p optimizedfor f in src/*.png; do name=$(basename "$f" .png) imgsqz "$f" -f webp -q 75 -o "optimized/$name.webp"donemkdir -p optimizedfor f in src/*.png set name (basename $f .png) imgsqz $f -f webp -q 75 -o "optimized/$name.webp"endNew-Item -ItemType Directory -Force optimized | Out-NullGet-ChildItem src\*.png | ForEach-Object { imgsqz $_.FullName -f webp -q 75 -o "optimized/$($_.BaseName).webp"}Parallel batches
Section titled “Parallel batches”imgsqz processes its own inputs sequentially. To use all your cores, fan out with
xargs or GNU parallel, one file per process:
# 4 files at a time with xargsls *.png | xargs -P 4 -I{} imgsqz {} -f webp -q 75 --quiet
# GNU parallelparallel imgsqz {} -f webp -q 75 --quiet ::: *.pngNext: Output paths & naming.