-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcwebp.ps1
More file actions
29 lines (25 loc) · 894 Bytes
/
cwebp.ps1
File metadata and controls
29 lines (25 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 定义参数
param (
[Parameter(Mandatory=$true, Position=0)]
[string]$directoryPath
)
# 检查目录是否存在
if (-not (Test-Path -Path $directoryPath -PathType Container)) {
Write-Host "目录不存在,请检查路径是否正确。" -ForegroundColor Red
exit
}
# 获取目录中的所有 PNG 文件
$pngFiles = Get-ChildItem -Path $directoryPath -Filter "*.png" -Recurse -File
# 遍历每个 PNG 文件并转换为 WEBP
foreach ($pngFile in $pngFiles) {
$outputPath = $pngFile.FullName -replace '\.png$', '.webp'
Write-Host "正在转换 $($pngFile.FullName) 为 $outputPath ..." -NoNewline
try {
.\cwebp.exe -q 85 $($pngFile.FullName) -o $outputPath
Write-Host " 完成。" -ForegroundColor Green
} catch {
Write-Host " 失败。" -ForegroundColor Red
Write-Error $_
}
}
Write-Host "所有文件转换完成。"