-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpToPng.ps1
More file actions
30 lines (23 loc) · 1.02 KB
/
webpToPng.ps1
File metadata and controls
30 lines (23 loc) · 1.02 KB
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
30
Param(
[Parameter(Mandatory=$true)]
[string]$folder
)
Write-Output $folder
$files = Get-ChildItem -Path $folder -Recurse -Force -Include *.webp
#Write-Output $files
foreach($inputFile in $files){
#Write-Output $inputFile
#Call dwebp
$inputFilePath = $inputFile.FullName
$outputFilePath = Split-Path -Path $inputFile.FullName
$outputFilePath = $outputFilePath + "\" + [System.IO.Path]::GetFileNameWithoutExtension($inputFilePath) + ".png"
$args = $inputFilePath + " -o " + $outputFilePath
Start-Process dwebp -ArgumentList $args -Wait
$originalFileSize = (Get-Item $inputFilePath).length
$optimizedFileSize = (Get-Item $outputFilePath).length
#Prepare output
$savedBytes = $optimizedFileSize - $originalFileSize
$savedPercentage = [math]::Round((($optimizedFileSize/$originalFileSize) * 100) - 100)
$message = $inputFilePath + " " + $outputFilePath + " " + $savedBytes + "bytes " + $savedPercentage + "%"
Write-Output $message
}