img2webp
Convert image files to WebP format
TLDR
Convert an image to WebP
SYNOPSIS
img2webp [options] input_files... -o output_file.webp
PARAMETERS
input_files...
One or more input image files (e.g., .png, .jpg, .tiff, .webp) to be converted. The order in which files are listed determines the animation sequence.
-o <file>
Specify the path for the output animated WebP file. This option is mandatory.
-q <float>
Compression quality (0-100). Higher values result in better visual quality but larger file sizes. Default is 75.
-loop <int>
Number of times the animation should loop. Use 0 for an infinite loop. Default is 0.
-duration <int>
Duration of each frame in milliseconds. This value applies to all frames unless specified individually per frame. Default is 100ms.
-kmin <int>
Minimum distance between keyframes (inclusive). Keyframes are frames that are encoded completely without reference to previous frames. Default is 9.
-kmax <int>
Maximum distance between keyframes (inclusive). Default is 17.
-lossy
Use lossy compression for all frames. This is the default if -q is used.
-lossless
Use lossless compression for all frames. This option overrides -q if both are present.
-mixed
Automatically decide between lossy and lossless compression for each frame, aiming for optimal compression based on content.
-min_size
Optimize the animation for minimal file size, potentially at the cost of some quality. This option implies -mixed.
-f <int>
Filter strength (0-100) for lossy compression. Higher values apply more deblocking and smoothing during encoding.
-mt
Use multi-threading for encoding, which can significantly speed up the conversion process on multi-core systems.
-v
Enable verbose output, showing encoding progress, statistics for each frame, and any warnings.
--help
Display a detailed help message with all command-line options and exit.
--version
Display version information of the img2webp tool and the underlying libwebp library, then exit.
DESCRIPTION
img2webp is a command-line tool designed for converting a sequence of input image files (such as PNG, JPEG, TIFF, and existing WebP images) into a single animated WebP file.
It is part of the official libwebp codec library, developed by Google, which focuses on efficient image compression. This utility provides comprehensive control over the animation parameters, including frame duration, looping count, quality settings, and various compression modes (lossy or lossless).
It's particularly useful for web developers and content creators who need to optimize animated graphics for web delivery, balancing file size with visual fidelity. By leveraging WebP's advanced compression algorithms, img2webp helps reduce bandwidth consumption and improve page load times on the web.
CAVEATS
The order of input files on the command line is crucial as it directly defines the sequence of frames in the resulting animated WebP file.
Memory usage can be substantial for very long animations or extremely high-resolution input images, as frames might be loaded into RAM during processing.
Input image format support (e.g., PNG, JPEG, TIFF) depends on the specific image decoding libraries that img2webp was compiled with on your system.
PER-FRAME OPTIONS
For more granular control, options like -duration or compression modes (-lossy, -lossless, -mixed) can be specified for individual frames by interleaving them with input filenames on the command line.
For example: img2webp -duration 100 frame1.png -duration 200 frame2.png -q 80 frame3.png -o output.webp
INPUT FILE FLEXIBILITY
img2webp can accept various image formats as input, including commonly used PNG, JPEG, and TIFF files, as well as existing WebP images. It automatically detects the format of each input file based on its headers.
HISTORY
img2webp is an integral component of the libwebp project, which was open-sourced by Google in 2010. Initially, the project focused on optimizing static image compression with tools like cwebp. As the demand for efficient animated web content grew, the WebP format was extended to support animations. img2webp was developed to enable the creation of these animated WebP files, offering a modern, highly efficient alternative to older formats like GIF. Its ongoing development aims to continuously improve compression efficiency, encoding speed, and promote broader adoption of WebP on the web.