9

I want to convert my photos from jpg, gif, and png to WebP format.

When I'm trying to use CMD for using cwebp command, I got this error message :

'cwebp' is not recognized as an internal or external command, operable program or batch file.

What should do I do?

I've downloaded all the files needed such as libwebp-0.4.0-windows-x86.zip and WebpCodecSetup.exe.

Even I've installed Visual Studio to use its command prompt, but didn't work! Is there anyone who can help me?

One more question:

Is anyone know any tool to reduce image size without losing its quality?

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Hosein
  • 179
  • 1
  • 2
  • 10
  • Issue resolved with this [softeware](https://dl.dropboxusercontent.com/u/44167254/Programme/webp/webp_convert_GUI.exe) – Hosein Jun 30 '14 at 07:55
  • Why don't you pose and answer your answer to make clear to everyone that problem has been solved @HoseinBL? – marol Jun 30 '14 at 07:57
  • I just found a Webp GUI ! – Hosein Jun 30 '14 at 08:15
  • Okay, what I meant is that on this site, when you know an answer to your own question, you are suggested to post the answer and accept it so that everyone can see that problem has been resolved. – marol Jun 30 '14 at 08:28
  • I can't ! cause my reputation score is less than 10 :( – Hosein Jun 30 '14 at 09:38

3 Answers3

24

Download cwebp binaries (.exe) and run it with PowerShell:

# tip: on windows explorer shift + right-click a directory and copy its path
$dir = "path/to/photos/directory"

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

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"

  C:\webp-converter\libwebp-0.6.1-windows-x64\bin\cwebp.exe $img.FullName -o $outputName
}

See also cwebp options.

pldg
  • 2,427
  • 3
  • 22
  • 37
  • 3
    This is no April Fools joke, runs perfect, if one does add the **bin** folder to the PATH (windows environment variables) you can just type `cwebp -q 75 -m 6 -af -f 50 -sharpness 0 -mt -v -progress $img.FullName -o $outputName` for example. – lowtechsun Sep 24 '18 at 11:14
  • How do i make the last link work with spaces in the path? Instead of `C:\webp-converter\libwebp-0.6.1-windows-x64\bin\cwebp.exe $img.FullName -o $outputName` to be `C:\Program Files\a lot of spaces in the path\bin\cwebp.exe $img.FullName -o $outputName`. Thanks. – EPurpl3 Jul 10 '19 at 14:21
  • 1
    @EPurpl3 this may help: https://stackoverflow.com/questions/18537098/spaces-cause-split-in-path-with-powershell – pldg Jan 11 '20 at 20:48
  • @pldg How could we make this work recursively? I have a branch with many subfolders with images. – Mirjana Katalina May 11 '21 at 23:42
2

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
Mylsel
  • 121
  • 7
0

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
lowtechsun
  • 1,915
  • 5
  • 27
  • 55