We should use WebP because it offers better compression than traditional image formats like JPEG and PNG, resulting in smaller file sizes without sacrificing quality. This leads to faster website load times, improved user experience, and reduced bandwidth consumption, which can lower hosting costs and improve SEO.

cwebp can be used to convert image formats (PNG, JPEG, TIFF, WebP, or raw Y’CbCr) to the WebP format.

Here is how you can convert the webp using cwebp tool

Download and install cwebp the precompiled binaries for your operating system from Google’s WebP page

In command line or terminal, run the following command to convert a single image:

cwebp input.jpg -o output.webp

Bulk conversion

For bulk conversion of JPG/PNG files in a directory, use the script below.

#!/bin/bash 

echo "Converting to webp ..."

for file in *.png; do
	outfile="${file%%.*}"
	echo "$outfile"
	cwebp -q 80 "$file" -o "$outfile.webp"
done

for file in *.jpg; do
	outfile="${file%%.*}"
	echo "$outfile"
	cwebp -q 80 "$file" -o "$outfile.webp"
done


exit 0
read  -n 1 -p "Input Selection:" mainmenuinput

Refrence