7

我想将我的照片从 jpg、gif 和 png 转换为WebP格式。

当我尝试使用 CMD 来使用 cwebp 命令时,我收到了以下错误消息:

'cwebp'不被识别为内部或外部命令、可运行程序或批处理文件。

我该怎么办?

我已经下载了所有需要的文件,例如libwebp-0.4.0-windows-x86.zipWebpCodecSetup.exe

即使我已经安装了 Visual Studio 来使用它的命令提示符,但是没有用!有谁能帮助我吗?

还有一个问题:

有谁知道有什么工具可以在不损失质量的情况下减小图像大小?

4

3 回答 3

18

下载cwebp 二进制文件(.exe) 并使用 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
}

另请参阅cwebp 选项

于 2018-04-01T20:44:55.227 回答
2

从 Windows 命令行 (CMD) 将任何图像格式转换为 webp

从此页面 下载最新的 webp 版本

我下载了这个包,因为我的系统是 32 位 windows 10

提取它并设置环境变量(按照以下步骤)

点击开始按钮输入“查看高级系统设置”并打开(这一步在win xp或win 7可能不同)点击环境变量>用户变量>新建>变量名:路径变量值:C:\libwebp-1.0.2- windows-x86\bin

现在打开 CMD > 转到图像文件夹运行以下命令

cwebp -q 50 -m 6 -af -f 50 -sharpness 0 -mt -v -progress source_img.jpg -o converted.webp
于 2019-06-10T13:22:51.593 回答
0

从 Google下载cwebp 二进制文件 (.exe)后,您可以使用 PowerShell 运行它。

然后将bin目录添加到您将 cwebp 库提取到 Windows PATH 的位置。例如,这是这样C:\downloads\libs\LibWebP\bin的。如果您不知道如何执行此操作,请搜索“如何向 Windows PATH 添加内容”。这是一个示例链接

如果您需要从当前目录遍历每个子目录,您可以在下面执行此操作,而不是将路径粘贴到脚本中的当前目录并对目录中的每个文件夹执行此操作。

# 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
于 2018-09-25T07:39:30.337 回答