I recently poked around some command-line tools for compression. There are a lot of options, but the best seem to be pngquant and jpegoptim. They are fairly cross-platform and free. Both big bonuses in my book.
I want to use CLI tools because they:
- Work across entire projects, not one file at a time
- Are easy to automate (CI, build scripts, pre-deploy steps)
- Produce consistent, repeatable results
- Are not GUI tools which means no manual exporting required

Compressed using pngquant - 59,449 bytes
Step 1: Install the Tools
macOS (Homebrew)
brew install pngquant jpegoptimLinux
Ubuntu / Debian:
sudo apt update
sudo apt install pngquant jpegoptimFedora:
sudo dnf install pngquant jpegoptimArch:
sudo pacman -S pngquant jpegoptimYou can then verify installation with:
pngquant --version
jpegoptim --versionStep 2: Compress PNGs
Single PNG file compression
pngquant --quality=65-85 --force --ext .png image.pngRecursively compress all PNGs in a project
find ./website-folder -type f -name "*.png" -exec pngquant --skip-if-larger --ext .png --quality=65-85 {} \;This command recursively finds all PNG files, compresses them in place, preserves filenames, and applies a quality range suitable for most web UI and illustration assets. It will skip the file if larger, meaning that it won't try to recompress files that it has already compressed.
Step 3: Compress JPGs
Single JPG file compression
jpegoptim --strip-all --max=85 image.jpgRecursively compress all JPGs in a project
find ./website-folder \( -iname "*.jpg" -o -iname "*.jpeg" \) -type f -exec jpegoptim --strip-all --max=85 {} \;--max=85 applies strong compression with minimal visual loss, while --strip-all removes EXIF and metadata. Files are overwritten in place.
Optional: Parallel Processing!
Parallel execution is especially useful on Linux servers and modern multi-core Macs.
# PNGs
find ./website-folder -type f -name "*.png" -print0 \
| xargs -0 -P 4 pngquant --force --ext .png --quality=65-85
# JPGs
find ./website-folder \( -iname "*.jpg" -o -iname "*.jpeg" \) -type f -print0 \
| xargs -0 -P 4 jpegoptim --strip-all --max=85 Increase the -P value based on available CPU cores. These commands are safe for CI runners and build servers.
Optional: Skip Small Images
You can avoid processing files that won’t meaningfully benefit from compression.
# PNGs larger than 50KB
find ./website-folder -type f -name "*.png" -size +50k \
-exec pngquant --force --ext .png --quality=65-85 {} \;
# JPGs larger than 50KB
find ./website-folder \( -iname "*.jpg" -o -iname "*.jpeg" \) -type f -size +50k \
-exec jpegoptim --strip-all --max=85 {} \;