mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
Added PIL dependency and added pixel dimentions autodetection
This commit is contained in:
parent
3103969bdc
commit
6324c805eb
1 changed files with 19 additions and 2 deletions
|
@ -8,7 +8,9 @@ __author__ = "Wuzzy"
|
||||||
__license__ = "MIT License"
|
__license__ = "MIT License"
|
||||||
__status__ = "Development"
|
__status__ = "Development"
|
||||||
|
|
||||||
import shutil, csv, os, tempfile, sys, getopt
|
import shutil, csv, os, tempfile, sys, getopt, glob
|
||||||
|
from PIL import Image
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
# Helper vars
|
# Helper vars
|
||||||
home = os.environ["HOME"]
|
home = os.environ["HOME"]
|
||||||
|
@ -31,7 +33,18 @@ make_texture_pack = True
|
||||||
# If True, prints all copying actions
|
# If True, prints all copying actions
|
||||||
verbose = False
|
verbose = False
|
||||||
|
|
||||||
PXSIZE = 16
|
PXSIZE = None
|
||||||
|
|
||||||
|
def detect_pixel_size(directory):
|
||||||
|
sizes = []
|
||||||
|
for filename in glob.glob(directory + '/**/*.png', recursive=True):
|
||||||
|
with Image.open(filename) as img:
|
||||||
|
sizes.append(img.size)
|
||||||
|
if not sizes:
|
||||||
|
return 16 # Default to 16x16 if no PNG files are found
|
||||||
|
most_common_size = Counter(sizes).most_common(1)[0][0]
|
||||||
|
print(f"Autodetected pixel size: {most_common_size[0]}x{most_common_size[1]}")
|
||||||
|
return most_common_size[0]
|
||||||
|
|
||||||
syntax_help = appname+""" -i <input dir> [-o <output dir>] [-d] [-v|-q] [-h]
|
syntax_help = appname+""" -i <input dir> [-o <output dir>] [-d] [-v|-q] [-h]
|
||||||
Mandatory argument:
|
Mandatory argument:
|
||||||
|
@ -83,6 +96,9 @@ Syntax:""")
|
||||||
elif opt == "-p":
|
elif opt == "-p":
|
||||||
PXSIZE = int(arg)
|
PXSIZE = int(arg)
|
||||||
|
|
||||||
|
if PXSIZE is None:
|
||||||
|
PXSIZE = detect_pixel_size(base_dir)
|
||||||
|
|
||||||
if base_dir == None:
|
if base_dir == None:
|
||||||
print(
|
print(
|
||||||
"""ERROR: You didn't tell me the path to the Minecraft resource pack.
|
"""ERROR: You didn't tell me the path to the Minecraft resource pack.
|
||||||
|
@ -110,6 +126,7 @@ if len(output_dir_name) == 0:
|
||||||
output_dir_name = "New_MineClone_2_Texture_Pack"
|
output_dir_name = "New_MineClone_2_Texture_Pack"
|
||||||
|
|
||||||
# FUNCTION DEFINITIONS
|
# FUNCTION DEFINITIONS
|
||||||
|
|
||||||
def colorize(colormap, source, colormap_pixel, texture_size, destination):
|
def colorize(colormap, source, colormap_pixel, texture_size, destination):
|
||||||
os.system("convert "+colormap+" -crop 1x1+"+colormap_pixel+" -depth 8 -resize "+texture_size+"x"+texture_size+" "+tempfile1.name)
|
os.system("convert "+colormap+" -crop 1x1+"+colormap_pixel+" -depth 8 -resize "+texture_size+"x"+texture_size+" "+tempfile1.name)
|
||||||
os.system("composite -compose Multiply "+tempfile1.name+" "+source+" "+destination)
|
os.system("composite -compose Multiply "+tempfile1.name+" "+source+" "+destination)
|
||||||
|
|
Loading…
Reference in a new issue