-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpngToWebp.ps1
More file actions
25 lines (20 loc) · 982 Bytes
/
pngToWebp.ps1
File metadata and controls
25 lines (20 loc) · 982 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
Param(
[Parameter(Mandatory=$true)]
[string]$folder
)
$files = get-childitem $folder -recurse -force -include *.jpg, *.png
foreach($inputFile in $files){
#Call cwebp
$inputFilePath = $inputFile.FullName
$outputFilePath = Split-Path -Path $inputFile.FullName
$outputFilePath = $outputFilePath + "\" + [System.IO.Path]::GetFileNameWithoutExtension($inputFilePath) + ".webp"
$args = "-q 80 " + $inputFilePath + " -o " + $outputFilePath
Start-Process cwebp -ArgumentList $args -Wait
$originalFileSize = (Get-Item $inputFilePath).length
$optimizedFileSize = (Get-Item $outputFilePath).length
#Prepare output
$savedBytes = $originalFileSize - $optimizedFileSize
$savedPercentage = [math]::Round(100-($optimizedFileSize / $originalFileSize)*100)
$message = $inputFilePath + " " + $outputFilePath + " " + $savedBytes + "bytes " + $savedPercentage + "%"
Write-Output $message
}