TIL: Optimizing WebP files with cwebp
WebP is a newer image format intended to provide smaller images for the web. Tools like Sketch provide the ability to export assets as WebP, but I've noticed the exports still seemed larger and almost equivalent to JPEG exports. For JPEG and PNG exports, you can use tools like ImageOptim to reduce the file sizes even further, but I haven't found a similar tool for WebP files.
I did find the cwebp CLI however, which in my testing so far can reduce the exported WebP file size in half. Here's the command I use:
-m
: Specify the compression method to use. This parameter controls the trade off between encoding speed and the compressed file size and quality. Possible values range from 0 to 6. Default value is 4. When higher values are used, the encoder will spend more time inspecting additional encoding possibilities and decide on the quality gain. Lower value can result in faster processing time at the expense of larger file size and lower compression quality.-af
: Turns auto-filter on. This algorithm will spend additional time optimizing the filtering strength to reach a well-balanced quality.
Related: Quick script to convert JPEG/PNG images to WebP and AVIF