To convert JPG or other image formats to WebP, you can use the WebP command line converter tool provided by Google. You can download the WebP converter tool from https://developers.google.com/speed/webp/download
(Click Download for Windows).
Once downloaded, extract the folder to C:\ directory or wherever else you like (you will need the path to converter tool later). After extracting the folder, open Command Prompt with administrator rights.
In the command prompt window, enter cd "path to the converter tool's bin folder"
and press Enter, for example, cd C:\libwebp-1.2.4-windows-x64\bin
.
Next, enter the following command line to convert a JPG image (or other image format) to WebP format.
cwebp.exe -q [quality number] [path to the image you want to convert] -o [path to save the converted image]
For example, the command line below will convert the image in C:\images\Bali.jpg with quality set as 50 (with 0 being the worst, 100 being the best quality, and 75 being the default value if not specified) and save the converted image as C:\images\Bali.webp.
cwebp.exe -q 50 c:\images\Bali.jpg -o c:\images\Bali.webp
After executing the command line, you can find the converted WebP image in the directory you have entered in the executed command line.
Batch convert JPG to WebP
To bulk convert JPG or other image format to WebP, follow the steps in the “Batch convert WebP to JPG” section above until the step where you need to enter command line. Then, use the command lines below instead to convert JPG to WebP. To enter multiple lines of commands, press Shift + Enter to go to next line without executing the command.
$dir = "c:\images" $images = Get-ChildItem $dir foreach ($img in $images) { $outputName = $img.DirectoryName + "\" + $img.BaseName + ".webp" C:\libwebp-1.2.4-windows-x64\bin\cwebp.exe $img.FullName -o $outputName }
Replace C:\images with the actual directory where the images you want to convert are stored. In addition, replace C:\libwebp-1.2.4-windows-x64\bin\cwebp.exe with the actual path to the webp.exe tool which you have extracted earlier.
The command lines above will convert all images in the C:\images folder, regardless of their formats, to WebP format using the cwebp.exe tool.
After executing the command, you can see the conversion progress directly in the Windows Terminal as it converts the images to WebP format. Once the WebP conversion is completed, you can find the converted images in the same folder where the original images are stored.
Thanks to WindowsDigitals.com for such a great article.