Skip to content

Compressing images

The core job of imgsqz is making images smaller. This guide covers the quality knob, lossless modes, and tips for squeezing each format.

-q, --quality takes an integer from 1 to 100. Lower means smaller files and more compression artifacts; higher means larger files and better fidelity. The default is 80.

Terminal window
# Aggressive — small files, visible artifacts at close inspection
imgsqz photo.jpg -q 50
# Default — a strong balance for most web imagery
imgsqz photo.jpg -q 80
# High fidelity — larger files, near-original quality
imgsqz photo.jpg -q 92
GoalFormatQuality
Photographic web imageswebp75
Smallest modern formatavif50–55
Maximum compatibilityjpg80
Screenshots / UI / textpng (lossless) or webp --lossless
Flat-color graphics, logospng80

To shrink a JPG and keep it a JPG, just set the format to match (or rely on the default for JPG sources):

Terminal window
# Re-encode a JPG at quality 75 (mozjpeg makes it smaller than most originals)
imgsqz big.jpg -f jpg -q 75 --no-timestamp -o big.jpg

For PNG-to-PNG, lower quality enables palette quantization for big wins on graphics:

Terminal window
imgsqz logo.png -f png -q 70

--lossless switches WebP, AVIF and PNG into a mode that reconstructs every pixel exactly — ideal for screenshots, diagrams, and anything with sharp text.

Terminal window
# Lossless WebP — pixel-perfect, still smaller than PNG for many images
imgsqz screenshot.png -f webp --lossless
# Lossless AVIF
imgsqz diagram.png -f avif --lossless

If color isn’t needed, --grayscale drops the chroma channels and shrinks the file further:

Terminal window
imgsqz scan.jpg --grayscale -q 80

Great for document scans, line art, and black-and-white photography.

imgsqz prints the before/after for every file:

photo.jpg
→ photo_20260611_132517.jpg
3.10 MB → 488.21 KB (↓ 84.6%)
  • ↓ 84.6% — the output is 84.6% smaller than the input.
  • ↑ 12.0% — the output is 12% larger (can happen when re-encoding an already-optimized file, or with lossless modes). If you see this, try a lower quality, a different format, or leave the original as-is.

Produce several candidates and compare sizes, then keep the winner:

Terminal window
for q in 50 65 80; do
imgsqz photo.jpg -f webp -q $q -o "out/photo-q$q.webp"
done
ls -lhS out/

Next: Converting formats.