From 8b480d3a08c7ccf327ef3f04a1cc81c547edbdfe Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Wed, 27 Jul 2022 19:35:27 -0300 Subject: Pragmatically prepare a lot of mobs --- README | 17 +++++++++++ mobs.py | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100755 mobs.py diff --git a/README b/README index acb9ea7..75a72a6 100644 --- a/README +++ b/README @@ -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 + + diff --git a/mobs.py b/mobs.py new file mode 100755 index 0000000..129d023 --- /dev/null +++ b/mobs.py @@ -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) + -- cgit v1.2.3-60-g2f50