Skip to content

Format behavior

imgsqz doesn’t just pass your file to a generic encoder — it applies tuned sharp settings per format. This page documents exactly what happens for each -f value.

sharp(...).jpeg({ quality, mozjpeg: true, progressive: true })
  • mozjpeg encoder — meaningfully smaller files than the standard JPEG encoder at the same quality.
  • Progressive — renders top-to-bottom in increasing detail; usually a touch smaller and nicer on slow connections.
  • No alpha channel (JPG has no transparency).
  • quality from -q (default 80).
sharp(...).png({ quality, compressionLevel: 9, palette: !lossless })
  • compressionLevel: 9 — maximum zlib compression (slower, smallest).
  • Palette quantization is on by default (palette: true), which uses quality to reduce the color palette — big savings for graphics, logos, and flat-color images.
  • Passing --lossless sets palette: false, preserving full color depth (no quantization) for a truly lossless PNG.
  • Alpha channel (transparency) preserved.
Terminal window
# Quantized PNG (smaller, palette-based)
imgsqz logo.png -f png -q 70
# Full-depth lossless PNG
imgsqz art.png -f png --lossless
sharp(...).webp({ quality, lossless, effort: 5 })
  • effort: 5 — a balanced CPU/size setting (range is 0–6; higher is slower and slightly smaller).
  • --lossless switches to lossless WebP (exact pixels, alpha preserved).
  • Alpha channel preserved in both modes.
  • Excellent default choice for the web.
Terminal window
imgsqz photo.png -f webp -q 75 # lossy
imgsqz screenshot.png -f webp --lossless # lossless
sharp(...).avif({ quality, lossless, effort: 5 })
  • effort: 5 — balanced encode speed vs. size (range 0–9 in libvips; imgsqz uses 5).
  • --lossless for exact reconstruction.
  • Best-in-class compression for photos — typically smaller than WebP at similar perceived quality.
  • Encoding is more CPU-intensive than WebP/JPG; expect longer runs on large batches.
Terminal window
imgsqz photo.jpg -f avif -q 50 # great size for the web
sharp(...).tiff({ quality, compression: "lzw" })
  • LZW compression — lossless container compression suited to archival and print workflows.
  • quality is accepted for completeness; LZW is lossless, so the practical output is a losslessly compressed TIFF.
  • --lossless has no additional effect here (TIFF/LZW is already lossless).
Terminal window
imgsqz scan.png -f tiff
Flagjpgpngwebpaviftiff
--quality✅ (palette)⚪️ (LZW lossless)
--lossless⚪️✅ (disables palette)⚪️ (already lossless)
Transparency
--grayscale
--width/--height
--no-strip-metadata

✅ applies · ⚪️ accepted but no effect · ❌ not supported by the format

Regardless of format, every pipeline:

  1. Opens the source with failOn: "none" — tolerant of minor corruption so slightly malformed images still process.
  2. Auto-rotates using EXIF orientation (.rotate()), baking the upright orientation into the pixels.
  3. Applies resize → grayscale → metadata → encode, in that order (see Core concepts).