LinuxCommandLibrary

cwebp

TLDR

Convert an image to WebP format

$ cwebp [input.png] -o [output.webp]
copy
Convert with specific quality (0-100)
$ cwebp -q [80] [input.jpg] -o [output.webp]
copy
Create lossless WebP
$ cwebp -lossless [input.png] -o [output.webp]
copy
Resize during conversion
$ cwebp -resize [800] [600] [input.jpg] -o [output.webp]
copy
Convert with alpha channel preservation
$ cwebp -alpha_q [90] [input.png] -o [output.webp]
copy
Use near-lossless compression
$ cwebp -near_lossless [60] [input.png] -o [output.webp]
copy

SYNOPSIS

cwebp [options] inputfile **-o** outputfile.webp

DESCRIPTION

cwebp is Google's encoder for the WebP image format. WebP provides superior compression compared to JPEG and PNG while supporting both lossy and lossless modes, as well as animation and alpha transparency.
The encoder accepts PNG, JPEG, TIFF, and WebP inputs. For lossy compression, the -q parameter controls the quality-size tradeoff. For lossless, the -z parameter controls compression effort.
WebP is widely supported in web browsers and offers 25-34% smaller file sizes than JPEG at equivalent quality. The lossless mode typically achieves 26% smaller files than PNG.

PARAMETERS

-o FILE

Output WebP file path.
-q QUALITY
Compression quality (0-100, default 75). Higher is better quality.
-lossless
Encode image losslessly.
-near_lossless LEVEL
Near-lossless preprocessing (0-100, 0 is maximum preprocessing).
-alpha_q QUALITY
Alpha channel quality (0-100).
-resize WIDTH HEIGHT
Resize to specified dimensions.
-crop X Y W H
Crop the input image.
-preset NAME
Preset: default, photo, picture, drawing, icon, text.
-m METHOD
Compression method (0-6, higher is slower/better).
-z LEVEL
Lossless compression preset (0-9).
-v
Verbose output.

CAVEATS

Very high quality settings may produce files larger than the source. Some older software doesn't support WebP. Lossy WebP introduces artifacts similar to JPEG. Near-lossless mode modifies pixels slightly for better compression.

HISTORY

WebP was developed by Google and released in 2010, based on the VP8 video codec. The cwebp encoder is part of the libwebp reference implementation. WebP achieved widespread browser support by 2020 and is recommended for web image optimization.

SEE ALSO

dwebp(1), gif2webp(1), cjpeg(1), convert(1)

Copied to clipboard