Convert JPEG and PNG to WebP with the cwebp CLI Tool

Install and use the cwebp command-line encoder to convert JPEG, PNG, and other images to WebP with precise quality and compression controls.

cwebp is the official command-line encoder from Google’s libwebp library. It converts JPEG, PNG, TIFF, and other source formats to WebP with precise control over quality and compression, making it the most reliable and feature-complete tool for WebP encoding directly from the terminal.

Installation #

Install cwebp using your platform’s package manager or download prebuilt binaries from Google.

# macOS
brew install webp
# Ubuntu / Debian
sudo apt update && sudo apt install webp
# Fedora / RHEL
sudo dnf install libwebp-tools

For Windows, download the prebuilt binaries from the official Google distribution page: https://developers.google.com/speed/webp/download. Extract the archive and add the bin/ directory to your system PATH so that cwebp is available from any command prompt or PowerShell session.

Basic Usage #

Pass a source image and specify an output file with the -o flag. The encoder automatically detects the input format from the file header.

cwebp input.jpg -o output.webp

Key Flags #

Use these flags to tune encoding behaviour to your specific needs.

-q <0-100> — Lossy Quality #

Controls the quality of lossy encoding. 0 is lowest quality (smallest file), 100 is highest quality (largest file). The default is 75; a value of 80–85 is recommended for most photographic content.

cwebp -q 85 photo.jpg -o photo.webp

-lossless — Lossless Mode #

Encodes the image without any quality loss. Ideal for graphics, logos, and images with transparency that must be preserved exactly. Produces larger files than lossy mode. For a deeper look, see lossless compression.

cwebp -lossless logo.png -o logo.webp

-near_lossless <0-100> — Near-Lossless Pre-Processing #

Applies a pre-processing step that adjusts pixel values to improve compressibility while keeping visual quality nearly identical to the original. This flag is not a synonym for -lossless — it operates independently and enables its own near-lossless compression mode; do not combine the two flags. 0 means maximum pre-processing (most aggressive size reduction); 100 means no pre-processing is applied (the pixel values are passed through unchanged). A typical value is around 60.

cwebp -near_lossless 60 image.png -o image.webp

-m <0-6> — Encoding Method / Effort #

Controls the encoding effort. Higher values produce smaller files at the cost of longer encoding time. The default is 4; use 6 for maximum compression when time is not a constraint.

cwebp -q 80 -m 6 photo.jpg -o photo.webp

-mt — Multi-Threading #

Enables multi-threaded encoding to use multiple CPU cores. Add this flag whenever you are encoding large images or running on multi-core hardware.

cwebp -q 80 -mt photo.jpg -o photo.webp

-metadata — Metadata Preservation #

Controls which metadata chunks to copy into the output file. Accepted values are none, all, exif, icc, and xmp. The default strips all metadata.

# Keep only the ICC colour profile
cwebp -q 80 -metadata icc photo.jpg -o photo.webp

-resize — Resize During Conversion #

Resizes the image as part of the encoding step. Pass 0 for either dimension to scale proportionally while preserving the aspect ratio.

# Resize to 1200px wide, height auto-calculated
cwebp -q 80 -resize 1200 0 large.jpg -o thumb.webp

-crop — Crop During Conversion #

Crops a rectangular region from the source image before encoding. Coordinates are in pixels, measured from the top-left corner.

cwebp -crop 100 50 800 600 photo.jpg -o cropped.webp

-alpha_q <0-100> — Alpha Channel Quality #

Sets the quality of the alpha channel when encoding images with transparency. 100 preserves the alpha channel losslessly; lower values allow lossy compression of transparency data.

cwebp -q 80 -alpha_q 100 icon.png -o icon.webp

Common Examples #

The following examples cover the most frequent real-world conversion tasks.

# High quality photo
cwebp -q 85 photo.jpg -o photo.webp

# Lossless PNG conversion
cwebp -lossless logo.png -o logo.webp

# Resize to max 1200px wide and convert
cwebp -q 80 -resize 1200 0 large.jpg -o thumb.webp

# Strip all metadata for privacy
cwebp -q 80 -metadata none photo.jpg -o photo.webp

# Keep ICC profile for colour accuracy
cwebp -q 80 -metadata icc photo.jpg -o photo.webp

Decoding with dwebp #

The libwebp package also installs dwebp, the companion decoder that converts WebP files back to standard formats. Use it whenever you need to inspect an encoded file or restore an original.

# Decode a WebP back to PNG
dwebp input.webp -o output.png

# Decode to BMP
dwebp input.webp -bmp -o output.bmp

Use webpinfo to inspect the internal structure and metadata of any WebP file without decoding it:

webpinfo image.webp

The output shows the file version, chunk layout, dimensions, colour profile, and whether the file uses lossy or lossless encoding — useful for debugging and quality-checking a batch of converted images.

Prefer a browser-based workflow? Use our free online converter to encode images, or our WebP to PNG tool to decode them back — no installation required.

Was this page helpful?