PowerShell/Scripts/Scale-Pixel.ps1
2023-06-28 12:27:21 -06:00

33 lines
905 B
PowerShell

param(
[validatescript({ Test-Path $_ -PathType Any })]
[system.io.fileinfo]$in,
$out = (Split-Path -Parent $in),
$scale = 128
)
if (-not (Get-Command "magick" -ErrorAction SilentlyContinue)) {
Write-Host "There's no magick to work with!"
exit
}
if ($in -notmatch '\\$') {
$in += "\"
}
if (Test-Path $in -PathType container) {
$out_dir = "$out\$(Split-Path -Leaf $in)_x$scale\"
if (-not (Test-Path $out_dir)) {
New-Item "$out_dir" -ItemType directory
}
foreach ($image in Get-ChildItem "$in*" -Include *.png, *.jpg, *.gif) {
$scaled = "$out_dir$($image.BaseName)_x$scale$($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
}