如何在Windows 8.1中将我的照片转换为Google的WebP格式?

9
我想将我的照片从jpg、gif和png格式转换为WebP格式。
当我尝试使用CMD使用cwebp命令时,我收到了以下错误信息:
“'cwebp'不是内部或外部命令,可操作的程序或批处理文件。”
我应该怎么办?
我已经下载了所有需要的文件,如libwebp-0.4.0-windows-x86.zip和WebpCodecSetup.exe。
我甚至安装了Visual Studio以使用其命令提示符,但没有成功!有人能帮帮我吗?
还有一个问题:
是否有任何工具可以在不失去图像质量的情况下减小图像大小?

问题通过这个软件得到解决。 - Hosein
为什么不发表并回答您的答案,让每个人都清楚问题已经解决了呢,@HoseinBL? - marol
我刚发现了一个Webp GUI! - Hosein
好的,我的意思是在这个网站上,当你知道自己问题的答案时,建议您发布答案并接受它,这样每个人就可以看到问题已经解决了。 - marol
我不能!因为我的声望分数少于10 :( - Hosein
3个回答

24

下载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选项


3
这不是愚人节玩笑,完美运行。如果将bin文件夹添加到PATH(Windows环境变量)中,您只需键入cwebp -q 75 -m 6 -af -f 50 -sharpness 0 -mt -v -progress $img.FullName -o $outputName,例如。请注意,这里的意思是在Windows操作系统上使用命令行工具进行图像转换。 - lowtechsun
如何使最后一个链接在路径中包含空格时正常工作?将C:\webp-converter\libwebp-0.6.1-windows-x64\bin\cwebp.exe $img.FullName -o $outputName更改为C:\Program Files\路径中有很多空格\bin\cwebp.exe $img.FullName -o $outputName。谢谢。 - EPurpl3
1
@EPurpl3 这可能会有所帮助:https://dev59.com/8mMl5IYBdhLWcg3wRlPo - pldg
@pldg 我们如何以递归方式使其工作?我有一个包含许多子文件夹和图像的分支。 - Mirjana Katalina

2
将任何图像格式从Windows命令行(CMD)转换为webp 从页面下载最新的webp版本
我下载了包,因为我的系统是32位的Windows 10
解压并设置环境变量(按照以下步骤进行)
点击开始按钮输入“查看高级系统设置”并打开它(此步骤可能在win xp或win 7中不同) 单击环境变量>用户变量>新建>变量名:path 变量值: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

0

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

然后将 bin 目录添加到您提取 cwebp lib 的位置的 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接