Last active
June 2, 2023 15:26
-
-
Save bumbummen99/a094e4f3565741647c0ad7cacdf2f731 to your computer and use it in GitHub Desktop.
Small PowerShell script to bulk upscale all files within a directory using Real-ESRGAN
This file contains hidden or 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
# Requirements: | |
# | |
# You need to have Real-ESRGAN installed and within your PATH. | |
# You can get Real-ESRGAN at the offical repository at | |
# https://github.com/xinntao/Real-ESRGAN | |
# | |
# Installation: | |
# | |
# Copy the script into any directory that is in your PATH variable. | |
# You can call it from PS using the file name i.e. upscale. | |
# | |
# You can find more information on how to edit the PATH and other | |
# environment variables on the offical Microsoft documentation: | |
# https://learn.microsoft.com/en-us/windows/win32/procthread/environment-variables | |
# | |
# Usage: | |
# > upscale | |
# > upscale -needle *.png | |
# > upscale -needle *.png -extension webp -subdirectory ./target | |
# | |
# Author: Patrick Henninger | |
# License: GNU GPL v3 | |
# | |
PARAM ( | |
[string]$needle='*.jpg', | |
[string]$extension='png', | |
[string]$subdirectory='./upscaled' | |
) | |
if ($subdirectory) { | |
# Create folder if does not exist | |
if (-Not (Test-Path -Path $subdirectory)) { | |
New-Item -Path $subdirectory -ItemType 'Directory' -Force | |
} | |
# Make sure the path is good | |
$subdirectory = (Resolve-Path $subdirectory).Path | |
} | |
Get-ChildItem -Path (Get-Location).Path -Filter $needle | Foreach-Object { | |
# Only process files | |
if ($_.GetType().FullName -ne "System.IO.FileInfo") { | |
# We have to use return instead of continue here | |
# see: https://stackoverflow.com/a/7763698/5703628 | |
return | |
} | |
# Build the target file name | |
[string]$target = $_.Name + ".$extension" | |
# Prepend the subdirectory in case it is defined | |
if ($subdirectory) { | |
$target = "$subdirectory\$target" | |
} | |
# Upscale using Real-ESRGAN | |
realesrgan -i $_.FullName -o $target | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment