PowerShell/Pixel-Scale.ps1

29 lines
814 B
PowerShell
Raw Permalink Normal View History

2023-06-19 05:01:03 +00:00
param(
[validatescript({ Test-Path $_ -PathType Any })]
[system.io.fileinfo]$in,
$out = (Split-Path -Parent $in),
$scale = 128
)
if (!(Get-Command "magick.exe" -ErrorAction SilentlyContinue)) {
Write-Host "There's no magick.exe to work with!"
2023-06-19 05:13:05 +00:00
exit
2023-06-19 05:01:03 +00:00
}
if (Test-Path $in -PathType container) {
$out_dir = "$out\x$scale\"
if (!(Test-Path $out_dir)) {
New-Item "$out_dir" -ItemType directory
}
foreach ($image in Get-ChildItem "$in*" -Include *.png) {
$scaled = "$out_dir$($image.BaseName)$($image.Extension)"
Write-Host $scaled
magick $image.FullName -scale "$($scale * 100)%" $scaled
}
}
else {
$scaled = "$out\$($in.BaseName)-x$scale$($in.Extension)"
Write-Host $scaled
magick $in.FullName -scale "$($scale * 100)%" $scaled
}