Created
August 24, 2019 17:10
-
-
Save DRKV333/7047fba6bc18825b1448c06bb495a6e3 to your computer and use it in GitHub Desktop.
A quick and dirty script for hq2x-ifying tMoadLoader mods
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
from pyhq2x import hq2x | |
import sys | |
import glob | |
from os import path, rename | |
from PIL import Image | |
# This is quick and dirty script for converting the textures of an extracted tModLoader mod as described here: | |
# https://forums.terraria.org/index.php?threads/hq2x-and-other-image-filter-packs.51557/ | |
# This script also needs the python hq2x implementation, which can be found here: | |
# https://github.com/DRKV333/pyhq2x | |
def MakeTransparent(image, color): | |
pixdata = image.load() | |
width, height = image.size | |
for y in range(height): | |
for x in range(width): | |
if pixdata[x, y][0:3] == color: | |
pixdata[x, y] = (0, 0, 0, 0) | |
moddir = sys.argv[0] | |
images = glob.glob(path.join(moddir, "**", "*.png"), recursive=True) | |
for imgp in images: | |
if path.isfile(imgp + ".bak"): | |
print("skipping " + imgp) | |
continue | |
print(imgp) | |
img = Image.open(imgp) | |
img = img.convert("RGBA") | |
pLower = str.lower(imgp) | |
if "tile" in pLower and "projectile" not in pLower: | |
MakeTransparent(img, (255, 0, 255)) | |
# Thanks Thorium, can't you guys decide on one shade of magenta? | |
MakeTransparent(img, (247, 119, 249)) | |
MakeTransparent(img, (255, 109, 235)) | |
MakeTransparent(img, (251, 85, 249)) | |
smallWidth = img.width // 2 | |
smallHeight = img.height // 2 | |
if smallWidth < 1 or smallHeight < 1: | |
continue | |
imgSmall = img.resize((smallWidth, smallHeight), Image.NEAREST) | |
imgScaled = hq2x(imgSmall) | |
rename(imgp, imgp + ".bak") | |
imgScaled.save(imgp) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment