最开始因为懒,所以一直用的在线转换。虽然方便但也有个弊端,速度慢、广告多还涉及隐私问题。于是就动了自己转换的想法,看了下Google官方工具也是支持windows的,就懒得往WSL里面装了。

目前我使用winget安装:

1
2
3
4
winget install libwebp

# scoop
scoop install libwebp

安装完成后重新启动powershell就可以使用cweb命令了。

1
cwebp -q 质量(0-100,越小质量越差,默认是75) .\cloudflare.png(需要转换的图片) -o .\cloudflare.webp(转换后输出的图片)

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cwebp -q 80 .\cloudflare.png -o .\cloudflare.webp
Saving file '.\cloudflare.webp'
File: .\cloudflare.png
Dimension: 1200 x 800
Output: 9794 bytes Y-U-V-All-PSNR 54.05 51.73 51.72 53.13 dB
(0.08 bpp)
block count: intra4: 241 (6.43%)
intra16: 3509 (93.57%)
skipped: 3454 (92.11%)
bytes used: header: 235 (2.4%)
mode-partition: 2485 (25.4%)
Residuals bytes segment 1segment 2segment 3segment 4 total
macroblocks: 1% 3% 4% 92% 3750
quantizer: 27 27 27 18
filter level: 8 6 5 2

如果本地图片多,还可以写成脚本,批量执行。

1
2
3
4
5
$images = Get-ChildItem -Path (Get-Location) -Filter *.png
foreach ($image in $images) {
$fileName = $image.DirectoryName + "\" + $image.BaseName + ".webp"
cwebp.exe -q 80 $image.FullName -o $fileName
}