cwebp
Convert images to WebP format
TLDR
Compress a WebP file with default settings (q = 75) to the [o]utput file
Compress a WebP file with the best [q]uality and largest file size
Compress a WebP file with the worst [q]uality and smallest file size
Compress a WebP file and apply resize to image
Compress a WebP file and drop alpha channel information
SYNOPSIS
cwebp [options...] -o output.webp input.png
PARAMETERS
-o file, --output=file
Set output WebP file; stdout if omitted
-q float, --quality=float
Quality factor 0-100 (default 75); higher is better
-lossless
Encode in lossless mode
-lossless_near=quality
Near-lossless encoding (0-100)
-m int, --compression=int
Compression method 0 (fastest)-6 (slowest, best)
-preset preset
Preset: none, photo, picture, drawing, icon, text
-alpha_quality=quality
Alpha plane quality 0-100 (default 100)
-alpha_filter=method
Alpha filtering: none, fast, best (default)
-sns=strength
Spatial noise shaping 0-100
-size pixels
Target file size in pixels
-psnr target
Target PSNR in dB
-resize w h
Resize output to width x height
-crop x y w h
Crop input to x-offset, y-offset, width, height
-mt threads
Max threads for multithreading (0=auto)
-metadata=all|none|icc|exif
Copy metadata (default none)
-short
Use fast encoding shortcuts
-framing 0|1
Split into frames (for animation)
-loop count
Loop count for animations (default infinite)
--
End of options; treat rest as filenames
-v, --verbose
Print verbose output
-h, --help
Show help
-version
Print version info
DESCRIPTION
cwebp is a command-line utility from Google's libwebp library for encoding images into the WebP format, supporting both lossy and lossless compression. It excels at producing smaller file sizes compared to JPEG or PNG while maintaining visual quality, making it ideal for web optimization.
Key features include tunable quality settings (-q), advanced compression methods (-m), alpha channel handling for transparency, preset profiles for quick setups, and support for animated WebP via multi-frame inputs. Users can target specific file sizes (-size), PSNR values (-psnr), or apply spatial noise shaping for better quality at low bitrates.
It accepts inputs like PNG, JPEG, TIFF, and raw RGB/YUV, outputting single-frame or animated WebP files. Multithreading (-mt) speeds up processing on modern CPUs. cwebp is widely used in web development, image processing pipelines, and tools like ImageMagick. For best results, experiment with presets like photo, picture, or drawing via -preset.
Installation is via package managers (e.g., apt install webp) or compiling libwebp. It's lossless-capable but defaults to lossy mode unless specified.
CAVEATS
Lossy mode irreversible; test quality visually. Large inputs may consume high memory. Animated WebP requires specific flags like -loop. Not all browsers support WebP fully.
EXAMPLE
cwebp -q 90 -m 6 input.jpg -o output.webp
cwebp -lossless input.png -o out.webp
ANIMATION
cwebp -loop 10 frame*.png -o anim.webp for looping GIF-like WebP
HISTORY
Developed by Google as part of libwebp (first release 0.1.0 in 2010). WebP format announced May 2010 for efficient web images. cwebp evolved with VP8/VP9/AVIF influences; current stable ~1.4.x (2024). Widely adopted post-Chrome 9 support.


