Skip to content

Converting formats

Converting is just compressing into a different format. Set -f, --format and imgsqz reads your source (any format sharp understands) and writes the target.

Terminal window
imgsqz input.png -f webp # PNG → WebP
imgsqz input.jpg -f avif # JPG → AVIF
imgsqz input.webp -f jpg # WebP → JPG
imgsqz input.tiff -f png # TIFF → PNG
-f valueExtensionBest for
jpg (or jpeg).jpgPhotos, universal compatibility
png.pngGraphics, transparency, lossless
webp.webpModern all-rounder, great compression
avif.avifSmallest files for photos, modern browsers
tiff.tiffArchival / print workflows (LZW compressed)

WebP — the safe default

Excellent compression, supports transparency and lossless, and is supported by every current browser. If you’re unsure, choose webp.

AVIF — the smallest

Typically beats WebP by 20–50% on photos at similar quality. Use it where your audience’s browsers support it (all modern ones do).

JPG — maximum reach

When something must open everywhere — email, legacy apps, print shops — JPG with mozjpeg is still a great choice.

PNG — graphics & transparency

Logos, icons, screenshots with text, anything needing an alpha channel and crisp edges.

Terminal window
# PNG screenshot → compact WebP
imgsqz screenshot.png -f webp -q 80
# Huge camera JPG → tiny AVIF for the web
imgsqz IMG_4821.jpg -f avif -q 50 --width 1600
# WebP back to JPG for an app that can't read WebP
imgsqz asset.webp -f jpg -q 85
# PNG with transparency → lossless WebP (keeps the alpha channel)
imgsqz icon.png -f webp --lossless

WebP, AVIF and PNG all support an alpha channel, so transparency is preserved when converting between them. JPG has no transparency — converting a transparent PNG to JPG flattens the alpha (transparent areas become black/white depending on the source). If you need transparency, target webp, avif, or png.

Convert every PNG in a directory to WebP at once:

Terminal window
imgsqz *.png -f webp -q 75

Each file is written next to its source with a timestamp suffix. For predictable names or in-place replacement, see Output paths & naming and Replacing files in place.


Next: Resizing & fit modes.