Created
November 30, 2021 05:42
-
-
Save eddiezato/3839d41af802474381b04990807f5199 to your computer and use it in GitHub Desktop.
PowerShell script to process images in the current folder using realesrgan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string[]] $Filter = @("*.jpg","*.jpeg") | |
) | |
Get-ChildItem -Path * -File -Include $Filter | Foreach-Object { | |
$i = 0 | |
Write-Progress -Activity $_.Name -Status " $i%" -PercentComplete $i | |
$job = Start-Job -ArgumentList $_.Name,"temp.png","$($_.Basename)_new.png" -ScriptBlock { | |
realesrgan -i $args[0] -o $args[1] *>&1 | |
magick $args[1] -resize x3056 $args[2] *>&1 | |
} | |
while ($job.State -eq "Running") { | |
$outValue = Receive-Job $job | |
if ($outValue) { | |
$percent = ($outValue -as [string]).Replace(",", ".").Replace("%", "") -as [float] | |
if ($percent -and ($percent -ne $i)) { | |
$i = [Math]::Round($percent) | |
Write-Progress -Activity $_.Name -Status " $i%" -PercentComplete $i | |
} | |
} | |
Start-Sleep -Seconds 0.2 | |
} | |
Write-Host $_.Name -NoNewLine | |
Write-Host " [" -ForegroundColor Yellow -NoNewLine | |
Write-Host "ok" -ForegroundColor Green -NoNewLine | |
Write-Host "]" -ForegroundColor Yellow | |
} | |
Write-Progress -Activity "Done" -Completed | |
if (Test-Path -Path "temp.png") { Remove-Item -Path "temp.png" -Force } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment