that'll do

This commit is contained in:
secretspecter 2023-06-18 23:01:03 -06:00
parent bbb7487c60
commit 51fc1c6d31
2 changed files with 30 additions and 1 deletions

View file

@ -111,7 +111,7 @@ In PowerShell files and folders are called items. Some useful cmdlets for workin
Here's how to loop through files in a folder using [`Get-ChildItem`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-7.3#description):
```powershell
foreach ($image Get-ChildItem $path -Include *.png) {
foreach ($image Get-ChildItem .\images\* -Include *.png) {
Write-Host $image.BaseName
}
```

29
pixup.ps1 Normal file
View file

@ -0,0 +1,29 @@
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!"
Exit-PSHostProcess
}
if (Test-Path $in -PathType container) {
Write-Host $in.DirectoryName
$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
}