Skip to content

Recipes

A cookbook of ready-to-run commands. Copy, tweak the paths, ship.

Terminal window
imgsqz hero.png -f webp -q 75 --width 1600 --no-timestamp -o public/hero.webp

Generate AVIF + WebP + JPG with a <picture> fallback

Section titled “Generate AVIF + WebP + JPG with a <picture> fallback”
Terminal window
imgsqz hero.png -f avif -q 50 --width 1600 --no-timestamp -o dist/hero.avif
imgsqz hero.png -f webp -q 75 --width 1600 --no-timestamp -o dist/hero.webp
imgsqz hero.png -f jpg -q 82 --width 1600 --no-timestamp -o dist/hero.jpg
<picture>
<source srcset="/hero.avif" type="image/avif" />
<source srcset="/hero.webp" type="image/webp" />
<img src="/hero.jpg" alt="" width="1600" loading="lazy" />
</picture>

Build a responsive srcset (multiple widths)

Section titled “Build a responsive srcset (multiple widths)”
Terminal window
for w in 480 768 1200 1600; do
imgsqz hero.png -f webp -q 75 --width $w -o "dist/hero-$w.webp"
done
<img
src="/hero-1200.webp"
srcset="/hero-480.webp 480w, /hero-768.webp 768w, /hero-1200.webp 1200w, /hero-1600.webp 1600w"
sizes="(max-width: 768px) 100vw, 1200px"
alt=""
/>
Terminal window
imgsqz public/img/*.png -f webp -q 75 --quiet
Terminal window
imgsqz profile.jpg --width 256 --height 256 --fit cover -f webp -q 80 -o avatars/me.webp
Terminal window
for f in photos/*.jpg; do
imgsqz "$f" --width 320 --height 320 --fit cover -f webp -q 70 \
-o "thumbs/$(basename "${f%.jpg}").webp"
done
Terminal window
imgsqz *.JPG --replace -q 82 --width 2048 --quiet
Terminal window
imgsqz scan-*.png -f tiff --no-strip-metadata
Terminal window
imgsqz print-ready.tiff -f jpg -q 95 --no-strip-metadata

Compress PNG screenshots to small JPGs for docs/issues

Section titled “Compress PNG screenshots to small JPGs for docs/issues”
Terminal window
imgsqz Screenshot*.png -f jpg -q 80 --quiet

Pixel-perfect lossless WebP for UI screenshots

Section titled “Pixel-perfect lossless WebP for UI screenshots”
Terminal window
imgsqz ui-screenshot.png -f webp --lossless -o docs/ui.webp
Terminal window
imgsqz contract-scan.jpg --grayscale -q 85 -f png
{
"scripts": {
"img:optimize": "imgsqz public/img/*.png -f webp -q 75 --quiet"
}
}
Terminal window
imgsqz assets/**/*.png -f webp -q 75 --quiet
# non-zero exit on failure stops the pipeline
- name: Optimize images
run: |
npm install -g @wdalhaj/imgsqz
imgsqz public/img/*.png -f webp -q 75 --quiet
Terminal window
ls raw/*.jpg | xargs -P 8 -I{} imgsqz {} -f avif -q 50 --width 1600 --quiet
Terminal window
npx @wdalhaj/imgsqz photo.png -f webp -q 70