How to Compress and Convert Images to WebP via Terminal

You can do it easily from the terminal using either cwebp or ImageMagick.

Option 1 — Using cwebp (best compression)

Install:

Ubuntu / Debian

sudo apt install webp

macOS

brew install webp

Convert and compress:

cwebp input.png -q 80 -o output.webp

Useful quality presets

  • -q 90 → high quality
  • -q 80 → balanced
  • -q 70 → smaller file
  • -q 50 → aggressive compression

Example:

cwebp blog-cover.png -q 75 -o blog-cover.webp

Option 2 — Using ImageMagick

Install:

Ubuntu

sudo apt install imagemagick

macOS

brew install imagemagick

Convert:

magick input.png -quality 80 output.webp

Resize + compress:

magick input.png -resize 1600x900 -quality 80 output.webp

Batch convert all PNGs

for img in *.png; do
cwebp "$img" -q 80 -o "${img%.png}.webp"
done

Check final file size

ls -lh *.webp

Recommended for blog feature images

For fast-loading blog headers:

cwebp feature.png -q 78 -m 6 -o feature.webp
  • -m 6 = better compression effort
  • Great balance for web performance + sharp text