diff options
author | Jesusaves <cpntb1@ymail.com> | 2022-07-27 19:35:27 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2022-07-27 19:35:27 -0300 |
commit | 8b480d3a08c7ccf327ef3f04a1cc81c547edbdfe (patch) | |
tree | 357d7ec116b0655fa3596f5624652a34493ef9a2 | |
parent | 0ae2fb405f97e927c9ec18a5055a94301a28405b (diff) | |
download | updates-8b480d3a08c7ccf327ef3f04a1cc81c547edbdfe.tar.gz updates-8b480d3a08c7ccf327ef3f04a1cc81c547edbdfe.tar.bz2 updates-8b480d3a08c7ccf327ef3f04a1cc81c547edbdfe.tar.xz updates-8b480d3a08c7ccf327ef3f04a1cc81c547edbdfe.zip |
Pragmatically prepare a lot of mobs
-rw-r--r-- | README | 17 | ||||
-rwxr-xr-x | mobs.py | 105 |
2 files changed, 122 insertions, 0 deletions
@@ -35,3 +35,20 @@ They must be: Keep in mind that NC licenses are NOT open source, nor are they compatible with the GPL! + +---- +Other tools (Linux-only) + +Dependencies: +```sh +apt install imagemagick +pip3 install pillow opencv-python``` + +* mobs.py + * Converts everything in "ready-mobs" to proper image size for mob db. + but attribution isn't generated. Input is PNG, output is WebP. + Image name should be the faction + monster ID. Model `FFMM`. So an imperial + spearman is named `0001` and an arch wizard is named `0701`. + Attribution template is sent to ATTR.txt for convenience + + @@ -0,0 +1,105 @@ +#!/usr/bin/python3 + +import os, subprocess + +try: + from PIL import Image # I hate you +except ImportError: + import cv2 + +pwd = os.getcwd() +f = open("ATTR.txt", "w") +bf1=[];bf2=[] + +for it in os.listdir(pwd + "/ready-mobs"): + if not it.endswith("png"): + continue + + name = it.split(".")[0] + path = pwd + "/ready-mobs/" + + try: + mobid = int(name) + except: + print("ERROR: %s is not parseable" % it) + continue + + print("%s" % it) + + # Get image size + try: + img = Image.open(path+it) + w = img.width + h = img.height + except: + img = cv2.imread(path+it) + h, w = img.shape[:2] + + # Type 1 convertion + # Max: 420x600 + w5 = int(w); h5 = int(h) + + """ + # Fix dimensions, width is priority + if h > 600: + w5 += ((600-h) * w) / h # As float + h5 = 600 + if w > 420: + h5 += ((420-w) * h) / w # As float + w5 = 420 + """ + + # We resize based on "best dimension" + # Relies on Python 3 division behavior + if (w / h) >= 1: + # Width is the better one + h5 += ((420-w) * h) / w # As float + w5 = 420 + else: + # Height is the better one + w5 += ((600-h) * w) / h # As float + h5 = 600 + + # Forced sanitization + w5 = min(w5, 420) + h5 = min(h5, 600) + + # Convert + subprocess.call("convert %s/%s -resize %dx%d %s/95%04d.webp" % (path, it, w5, h5, path, mobid), shell=True) + + # Prepare the "BOSS" dimension + # 2200 x 1800 + w6 = int(w); h6 = int(h) + # We resize based on "best dimension" + # Relies on Python 3 division behavior + if (w / h) >= 1: + # Width is the better one + h6 += ((2200-w) * h) / w # As float + w6 = 2200 + else: + # Height is the better one + w6 += ((1800-h) * w) / h # As float + h6 = 1800 + + # Forced sanitization + w6 = min(w6, 2200) + h6 = min(h6, 1800) + + # Convert + subprocess.call("convert %s/%s -resize %dx%d %s/96%04d.webp" % (path, it, w6, h6, path, mobid), shell=True) + + # Save + bf1.append("\t95%04d NAME (AUTHOR)\t(CC BY SA)\t(SOURCE)\n" % (mobid)) + bf2.append("\t96%04d NAME (AUTHOR)\t(CC BY SA)\t(SOURCE)\n" % (mobid)) + +# Flush +for it in sorted(bf1): + f.write(it) +f.write("\n") +for it in sorted(bf2): + f.write(it) + +f.close() +print("\n\n*************************") +subprocess.call("cat %s/ATTR.txt" % pwd, shell=True) + |