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.
JPG (-f jpg / -f jpeg)
Section titled “JPG (-f jpg / -f jpeg)”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).
qualityfrom-q(default 80).
PNG (-f png)
Section titled “PNG (-f png)”sharp(...).png({ quality, compressionLevel: 9, palette: !lossless })compressionLevel: 9— maximum zlib compression (slower, smallest).- Palette quantization is on by default (
palette: true), which usesqualityto reduce the color palette — big savings for graphics, logos, and flat-color images. - Passing
--losslesssetspalette: false, preserving full color depth (no quantization) for a truly lossless PNG. - Alpha channel (transparency) preserved.
# Quantized PNG (smaller, palette-based)imgsqz logo.png -f png -q 70
# Full-depth lossless PNGimgsqz art.png -f png --losslessWebP (-f webp)
Section titled “WebP (-f webp)”sharp(...).webp({ quality, lossless, effort: 5 })effort: 5— a balanced CPU/size setting (range is 0–6; higher is slower and slightly smaller).--losslessswitches to lossless WebP (exact pixels, alpha preserved).- Alpha channel preserved in both modes.
- Excellent default choice for the web.
imgsqz photo.png -f webp -q 75 # lossyimgsqz screenshot.png -f webp --lossless # losslessAVIF (-f avif)
Section titled “AVIF (-f avif)”sharp(...).avif({ quality, lossless, effort: 5 })effort: 5— balanced encode speed vs. size (range 0–9 in libvips; imgsqz uses 5).--losslessfor 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.
imgsqz photo.jpg -f avif -q 50 # great size for the webTIFF (-f tiff)
Section titled “TIFF (-f tiff)”sharp(...).tiff({ quality, compression: "lzw" })- LZW compression — lossless container compression suited to archival and print workflows.
qualityis accepted for completeness; LZW is lossless, so the practical output is a losslessly compressed TIFF.--losslesshas no additional effect here (TIFF/LZW is already lossless).
imgsqz scan.png -f tiffHow flags map to formats
Section titled “How flags map to formats”| Flag | jpg | png | webp | avif | tiff |
|---|---|---|---|---|---|
--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
Always-on processing
Section titled “Always-on processing”Regardless of format, every pipeline:
- Opens the source with
failOn: "none"— tolerant of minor corruption so slightly malformed images still process. - Auto-rotates using EXIF orientation (
.rotate()), baking the upright orientation into the pixels. - Applies resize → grayscale → metadata → encode, in that order (see Core concepts).