How to convert image to WebP format. Free WebP Converter can help.

How to convert image to WebP format. Free WebP Converter can help.
Image by fancycrave1 from Pixabay

WebP is an image format developed by Google. It provides lossy and lossless compression for images on the web, along with animation and transparency. Plus, WebP provides a smaller file size and similar image quality compared to the popular image format JPEG, PNG, and GIF.

First, I saw this image format from the Google Developer tool PageSpeed insight(PSI). The PSI tool suggests using WebP image format to reduce the image size, therefore, reduce the page loading times.

So, I started to switch all my images to WebP image format for my blog. I use the online tool to do the conversion, but most of the image format conversion tools have limitations for the non-paid user. After a few searches, I found a WebP converter developed by Google. It's free to use and runs on the local machine. The WebP Converter is a command-line tool; it's not that user-friendly. So, below will demonstrate how to convert a single image and by batch to WebP format.

Preparation:

  1. Download libwebp-1.2.0-windows-x64.zip:https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.2.0-windows-x64.zip
  2. Select the file, right-click and click Extract All the libwebp-1.2.0-windows-x64.zip.

Single Image:

  1. Open Command Prompt, type "CD <file path contains libwebp-1.2.0-windows-x64 folder>\libwebp-1.2.0-windows-x64\bin" and press Enter.
  2. Type "cwebp <image path location you want to convert> -o <Path location you want to store the converted image>" and press Enter.

Example for command prompt:

Convert single image to WebP
Convert single image to WebP

By Batch:

The code below I found on StackOverflow. I make modifications to the code, it will create a folder called "converted" and store all the converted WebP in the folder.  I make modifications to the code, it will create a folder called "converted" and store all the converted WebP in the folder.

# on Windows Explorer, shift + right-click a directory and copy its path
# paste the path in $dir
$dir = "<folder path contains your images>"

#create a folder to store the converted images
$convertedFolderName = $dir + '\converted'
New-Item -Path $convertedFolderName -ItemType Directory

#get all files in the directory
$images = Get-ChildItem $dir

# loop through every images
foreach ($img in $images) {
    # output file will be written in the same directory
    # but with .webp extension instead of old extension
    $outputName = $img.DirectoryName + "\converted\" + $img.BaseName + ".webp"

    # copy-paste the path to cwebp program
    # and set its input and output parameters
    # more options https://developers.google.com/speed/webp/docs/cwebp
    C:\webp-converter\libwebp-0.6.1-windows-x64\bin\cwebp.exe $img.FullName -o
    $outputName 
}

Replace the $dir path to your folder, copy and paste the code above to the Powershell, then press Enter. All the images should be converted and store within the folder name "converted".

Next Post Previous Post
No Comment
Add Comment
comment url