-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_to_webp.ps1
34 lines (29 loc) · 1.22 KB
/
convert_to_webp.ps1
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
31
32
33
34
$inputFolder = ".\images\"
$outputFolder = ".\images\"
if (-Not (Test-Path -Path $outputFolder)) {
New-Item -ItemType Directory -Path $outputFolder
}
$imageFiles = Get-ChildItem -Path $inputFolder -File -Include @("*.png", "*.gif", "*.jpeg", "*.jpg", "*.bmp", "*.tiff", "*.ico", "*.cur", "*.apng", "*.avif", "*.heif", "*.heic") -Recurse
$convertSvg = Read-Host "Do you want to convert SVG files? (Y/N)"
if ($convertSvg -eq "Y" -or $convertSvg -eq "y") {
$svgFiles = Get-ChildItem -Path $inputFolder -File -Include @("*.svg") -Recurse
$imageFiles += $svgFiles
}
if ($imageFiles.Count -eq 0) {
Write-Output "No image files found in the input folder."
} else {
foreach ($imageFile in $imageFiles) {
$outputFile = Join-Path -Path $outputFolder -ChildPath ($imageFile.BaseName + ".webp")
& cwebp $imageFile.FullName -o $outputFile
}
Write-Output "Conversion completed!"
}
$deleteOriginal = Read-Host "Do you want to delete the original images? (Y/N)"
if ($deleteOriginal -eq "Y" -or $deleteOriginal -eq "y") {
foreach ($imageFile in $imageFiles) {
Remove-Item -Path $imageFile.FullName
}
Write-Output "Original images deleted!"
} else {
Write-Output "Original images not deleted."
}