LinuxCommandLibrary

img2webp

Convert image files to WebP format

TLDR

Convert an image to WebP

$ img2webp [path/to/image] -o [path/to/image.webp]
copy

SYNOPSIS

img2webp [options] infile -o outfile.webp

PARAMETERS

-lossless <0|1>
    Specify lossless encoding. 0 - Lossy(default) and 1 - Lossless.

-q
    Specify the quality factor between 0 and 100. Higher values results to high quality image, but bigger size.

-alpha_q
    Specify the alpha compression quality between 0 and 100. Use value 100 for lossless.

-m
    Specify the compression method to use, between 0 and 6. Method 0 is the fastest, but less compressed. Method 6 is the slowest, but better compressed.

-resize
    Resize picture to a given size

-mt
    Use multi-threading for encoding, if available.

-o
    Specify the output file name. Mandatory Parameter.

infile
    Specify the input file. Mandatory Parameter.

DESCRIPTION

The img2webp command is a command-line utility used to convert image files to the WebP format. WebP is a modern image format developed by Google that provides superior lossless and lossy compression for images on the web. img2webp allows you to reduce image file sizes while maintaining acceptable image quality, leading to faster website loading times and reduced bandwidth consumption. It supports a variety of input image formats and provides options for adjusting the compression level and other encoding parameters. The command is a wrapper around the WebP encoding library, making it relatively simple to use.

CAVEATS

The availability and specific features of img2webp depend on the version of the libwebp library installed on the system. Check your installed version for the exact set of supported options and capabilities.
Error handling might be limited, so check carefully the existance of infile and the access rights.
It has to be a single image file and not to batch convert. For batch convert use a wrapper script.

EXAMPLES

Convert image.png to image.webp using default settings:
img2webp image.png -o image.webp

Convert image.jpg to image.webp with a quality setting of 80:
img2webp -q 80 image.jpg -o image.webp

Convert image.png to image.webp using lossless compression:
img2webp -lossless 1 image.png -o image.webp

Convert image.jpg to image.webp with a quality of 70 and resize to 500x400:
img2webp -q 70 -resize 500 400 image.jpg -o image.webp

HISTORY

img2webp is part of the libwebp library developed by Google. The WebP format was first announced in 2010, and the associated tools, including img2webp, have been under continuous development since then. Its development aimed to create a more efficient image format for the web, improving upon existing formats like JPEG and PNG. img2webp's usage grew as WebP adoption increased among websites and content delivery networks looking to optimize image delivery.

SEE ALSO

cwebp(1), dwebp(1)

Copied to clipboard