Linux command
cwebp 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Convert an image to WebP
cwebp [input.png] -o [output.webp]
Convert with specific quality
cwebp -q [80] [input.jpg] -o [output.webp]
Create lossless WebP
cwebp -lossless [input.png] -o [output.webp]
Resize during conversion
cwebp -resize [800] [600] [input.jpg] -o [output.webp]
Convert with alpha channel
cwebp -alpha_q [100] [input.png] -o [output.webp]
Use near-lossless
cwebp -near_lossless [60] [input.png] -o [output.webp]
Maximum compression effort
cwebp -m 6 -q [80] [input.jpg] -o [output.webp]
Use a preset
cwebp -preset photo -q [80] [input.jpg] -o [output.webp]
说明
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 (animated PNG and WebP are not supported). For lossy compression, the -q parameter controls the quality-size tradeoff. For lossless, the -z parameter controls compression effort. Using -o - sends the encoded output to stdout. 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.
参数
- -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, default 100 = no preprocessing; 60 is typical). Triggers lossless mode.
- -alpha_q _QUALITY_
- Alpha channel quality (0-100, default 100 = lossless alpha).
- -resize _WIDTH_ _HEIGHT_
- Resize to the given dimensions. A value of 0 for one dimension preserves the aspect ratio.
- -crop _X_ _Y_ _W_ _H_
- Crop the input image to the rectangle at (_X_,_Y_) with width _W_ and height _H_.
- -preset _NAME_
- Preset: default, photo, picture, drawing, icon, text. Must appear before other options.
- -m _METHOD_
- Compression method (0-6, default 4; higher is slower but produces smaller files).
- -z _LEVEL_
- Lossless compression preset (0-9, 0 fastest / 9 slowest; a good default is 6).
- -exact
- Preserve RGB values in fully transparent areas (lossless only).
- -mt
- Use multi-threading if available.
- -v
- Verbose output.
FAQ
What is the cwebp command used for?
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 (animated PNG and WebP are not supported). For lossy compression, the -q parameter controls the quality-size tradeoff. For lossless, the -z parameter controls compression effort. Using -o - sends the encoded output to stdout. 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.
How do I run a basic cwebp example?
Run `cwebp [input.png] -o [output.webp]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -o _FILE_ do in cwebp?
Output WebP file path.