that'll do
This commit is contained in:
parent
bbb7487c60
commit
51fc1c6d31
|
@ -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
29
pixup.ps1
Normal 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
|
||||
}
|
Loading…
Reference in a new issue