WebP is an image format that provides lossless and lossy compression of images for use on the web. Linux Mint comes with an easy-to-use command-line software to convert images to .webp format.
First check the Linux Software Manager to ascertain that Webp is installed. In the search box of software manager enter "webp". Webp will appear in the middle of the list. If it is not marked as installed, then click the install button.
Installation of WebP provides three command line utilities:
- cwebp: For compression of an image file to the WebP format.
- dwebp: For decompression of an image file to a PNG, PAM, PPM or PGM formats.
- vwebp: For decompression and display of an image file.
Conversion of a single image file
Go the directory where the images are located. Right click on the directory name and select "Open in Terminal" option. To convert an image, enter the following command in a terminal window:
cwebp Input_filename.jpg -o Output_filename.webp
To convert and and resize an image, enter the following commmand in the terminal window:
cwebp -resize 180 0 Input_filename.jpg -o Output_filename.webp
This command will resize the width of the image to 180 pixels. The zero after 180 specifies automatic determination of the image height maintaining image aspect ratio.
If the files have the extension .JPEG, then change .jpg to .JPEG.
Batch conversion of many image files
For batch conversion of JPG (or JPEG) files to .webp format go the directory where the images are located. Right click on the directory name and select "Open in Terminal" option. For batch conversion of files, enter the following command in a terminal window:
for i in *.jpg; do cwebp -resize 0 300 "$i" -o "${i%.jpg}.webp"; done
This example command also includes an option (-resize 0 300) to resize the height of the image to 300 pixels. The zero before 300 specifies automatic determination of the image width maintaining image aspect ratio.