Created
October 18, 2022 09:07
-
-
Save arth2o/088078e5df479d5206550fa82497ba32 to your computer and use it in GitHub Desktop.
Batch Upscale Your .jpg Photos in a folder using AI and Python. Call Python3 ./script.py
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
# install | |
# Upscale Your Photos | |
# pip install super-image | |
# pip install pillow | |
from super_image import * | |
from PIL import Image | |
import os, sys, glob | |
from pathlib import Path | |
from datetime import datetime | |
def UpscaleImage(img_file, scale_value, newFileName): | |
img = Image.open(img_file) | |
model = EdsrModel.from_pretrained('eugenesiow/edsr-base', scale=scale_value) | |
photo = ImageLoader.load_image(img) | |
upscale = model(photo) | |
ImageLoader.save_image(upscale, './'+newFileName) | |
def listFilesInDir(): | |
dirs = glob.glob('./*.jpg') | |
dt = datetime.now() | |
ts = datetime.timestamp(dt) | |
for item in dirs: | |
p = Path(item) | |
extensions = "".join(p.suffixes) | |
newFileName = str(p).replace(extensions, "")+'_'+ str(ts) +'.png' | |
print(item); | |
UpscaleImage(item, 4, newFileName) | |
listFilesInDir(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment