From 51fc1c6d31e7a1e27b952a5ffc911137b5a84762 Mon Sep 17 00:00:00 2001 From: secretspecter Date: Sun, 18 Jun 2023 23:01:03 -0600 Subject: [PATCH] that'll do --- CrashCourse.md | 2 +- pixup.ps1 | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 pixup.ps1 diff --git a/CrashCourse.md b/CrashCourse.md index 17b6237..26f59ea 100644 --- a/CrashCourse.md +++ b/CrashCourse.md @@ -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 } ``` diff --git a/pixup.ps1 b/pixup.ps1 new file mode 100644 index 0000000..9acad36 --- /dev/null +++ b/pixup.ps1 @@ -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 +}