How to convert my photos to webp format of Google in windows 8.1?

爱⌒轻易说出口 提交于 2019-12-04 10:08:52

After you download cwebp binaries (.exe) from Google you can run it with PowerShell.

Copy and paste the code below in PowerShell and press enter to run it.

Read the comments in the snippet for more information.

# on Windows Explorer, shift + right-click a directory and copy its path
# paste the path in $dir
$dir = "path/to/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 + "\" + $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
}

To convert any image format to webp from Windows command line (CMD)

Download latest webp release from this page

I downloaded this package because my system is a 32 bit windows 10

Extract it and set environmental variable (follow below steps)

Click start button type "view advanced system settings" and open it (this step may differ in win xp or win 7) Click Environment Variables>User Variables>New>Variable Name:path Variable Value:C:\libwebp-1.0.2-windows-x86\bin

Now open CMD > Go to Image folder run following command

cwebp -q 50 -m 6 -af -f 50 -sharpness 0 -mt -v -progress source_img.jpg -o converted.webp

After you download cwebp binaries (.exe) from Google you can run it with PowerShell.

Then add the bin directory to where you extracted the cwebp lib to your Windows PATH. This is something like this C:\downloads\libs\LibWebP\bin for example. If you don't know how to do this search for "how to add something to windows PATH". Here is an example link.

If you need to go through each sub directory from the current directory you can do this below instead of pasting the path to the current directory in the script and doing so for each folder in the directory.

# get current directory
$initpath = Get-Location
# get all directories
foreach($path in Get-Childitem) {
    if ($path.Attributes -eq "Directory") {
        set-location $path.FullName
          # get all files in the directory
          $images = Get-ChildItem $dir

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

            # since you have the cwebp bin folder in PATH just type the command
            # more options https://developers.google.com/speed/webp/docs/cwebp
            cwebp -q 75 -m 6 -af -f 50 -sharpness 0 -mt -v -progress $img.FullName -o $outputName
          }
    }
}
set-location $initpath
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!