LinuxCommandLibrary

cwebp

Convert images to WebP format

TLDR

Compress a WebP file with default settings (q = 75) to the [o]utput file

$ cwebp [path/to/image_file] -o [path/to/output.webp]
copy

Compress a WebP file with the best [q]uality and largest file size
$ cwebp [path/to/image_file] -o [path/to/output.webp] -q [100]
copy

Compress a WebP file with the worst [q]uality and smallest file size
$ cwebp [path/to/image_file] -o [path/to/output.webp] -q [0]
copy

Compress a WebP file and apply resize to image
$ cwebp [path/to/image_file] -o [path/to/output.webp] -resize [width] [height]
copy

Compress a WebP file and drop alpha channel information
$ cwebp [path/to/image_file] -o [path/to/output.webp] -noalpha
copy

SYNOPSIS

cwebp [options] input_file -o output_file

PARAMETERS

-q quality_factor
    Specifies the quality factor between 0 and 100. Lower values produce smaller files with lower quality. Default is 75.

-lossless
    Encode the image losslessly.

-near_lossless level
    Use near-lossless image preprocessing. This option adjusts pixel values to help compressibility, but reduces visual quality.

-z level
    Specifies the compression level from 0 to 9, with 0 being the fastest and 9 being the slowest (best compression). Default is 6.

-m method
    Specifies the compression method to use, between 0 and 6. Method 0 is the fastest but yields larger file size. Method 6 is the slowest, but results in better compression. Default is 4.

-resize width height
    Resizes the image to the specified width and height.

-crop x y width height
    Crops the image to a rectangle starting at the specified coordinates (x, y) with the given width and height.

-alpha_q quality
    Specifies the quality for lossy compression of the alpha channel, between 0 and 100. Default is 100.

-o output_file
    Specifies the output file name.

-version
    Display the version number and exit.

-h, -help
    Display usage information.

-metadata string
    Copy metadata from the input to the output if present. Valid values are all, none, icc, exif, xmp (default: none)

DESCRIPTION

cwebp is a command-line tool for encoding images into the WebP format. WebP is a modern image format developed by Google that provides superior lossless and lossy compression for images on the web. It is designed to reduce file size while maintaining or improving image quality compared to older formats like JPEG and PNG.

The cwebp tool offers various options to control the encoding process, allowing users to optimize image compression based on their specific needs. This includes adjusting the quality, compression method, and other parameters. It supports encoding of multiple input formats including PNG, JPEG, TIFF and WebP to a single WebP output file.

Using cwebp can significantly reduce the bandwidth required to serve images, leading to faster page load times and a better user experience. It's widely used in web development, image processing, and digital asset management.

CAVEATS

The output file must be specified using the -o option. If the output file already exists, it will be overwritten without warning. Certain advanced features of WebP, such as animation or advanced alpha compression, may require other tools or libraries from the WebP ecosystem.

INPUT FORMATS

cwebp supports a variety of common image formats as input, including JPEG, PNG, TIFF, and WebP itself. The tool automatically detects the input format based on the file contents.

PERFORMANCE CONSIDERATIONS

The encoding process can be CPU-intensive, especially when using higher compression levels or lossless encoding. For batch processing or large images, consider using multiple cores or optimizing the encoding parameters to balance compression and speed.

HISTORY

WebP was first announced by Google in 2010. The cwebp tool was developed as part of the WebP project to provide a way to encode images into this new format. It has been continuously improved over the years with enhancements to compression algorithms, support for new features, and optimizations for performance.

SEE ALSO

dwebp(1), gif2webp(1)

Copied to clipboard