ASSETS UPDATE: Added references folder with 132 PNGs (resized/sharpened) + Created DEMO_FAZA1 folder structure
This commit is contained in:
122
scripts/utils/intelligent_resize.py
Normal file
122
scripts/utils/intelligent_resize.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
SOURCE_DIR = "/Users/davidkotnik/Desktop/referencne slike 2"
|
||||
|
||||
# --- CONFIGURATION: LOGIC FOR RESIZING ---
|
||||
# We define max dimension (width or height, whichever is larger).
|
||||
# The aspect ratio is always preserved.
|
||||
|
||||
RESIZE_RULES = [
|
||||
# --- MASSIVE (512px - 600px) ---
|
||||
# Buildings, large trees, Gronk (Giant Troll)
|
||||
{
|
||||
"keywords": ["zgradba", "hisa", "skedenj", "drevo_veliko", "gronk", "troll", "structure", "objekt", "rudnik", "vhod"],
|
||||
"size": 512
|
||||
},
|
||||
|
||||
# --- MEDIUM-LARGE (350px - 400px) ---
|
||||
# Regular trees, large animals, vehicles
|
||||
{
|
||||
"keywords": ["drevo", "krava", "konj", "medved", "auto", "traktor", "agregat", "sod", "kontejner", "vodnjak", "koca", "sotor"],
|
||||
"size": 384
|
||||
},
|
||||
|
||||
# --- MEDIUM (Standard Character Size: 256px) ---
|
||||
# Humans, zombies, standard props, furniture
|
||||
{
|
||||
"keywords": ["zombi", "kai", "ana", "ata", "mama", "love", "character", "kip", "postelja", "vreca", "miza", "stol", "klop", "kamen_srednji", "ograja"],
|
||||
"size": 256
|
||||
},
|
||||
|
||||
# --- SMALL-MEDIUM (128px - 192px) ---
|
||||
# Small animals, dogs, inventory items held in hand
|
||||
{
|
||||
"keywords": ["pes", "susi", "macka", "kokos", "zajec", "svinja", "ovca", "orodje", "kramp", "sekira", "motika", "lopata", "meč", "puska", "kamen", "grm", "trava"],
|
||||
"size": 192
|
||||
},
|
||||
|
||||
# --- SMALL (64px - 96px) ---
|
||||
# Insects, small items, icons, UI elements
|
||||
{
|
||||
"keywords": ["insekt", "mravlja", "cebela", "metulj", "hrosc", "muha", "komar", "polz", "dezevnik", "ikona", "item", "seme", "steklenica", "hrana", "ui", "gumb"],
|
||||
"size": 96
|
||||
}
|
||||
]
|
||||
|
||||
DEFAULT_SIZE = 256 # Fallback size if no keyword matches
|
||||
|
||||
def install_dependencies():
|
||||
pass # Pillow should be installed from previous step
|
||||
|
||||
def get_target_size(filename):
|
||||
"""Determine size based on filename keywords."""
|
||||
fname = filename.lower()
|
||||
|
||||
for rule in RESIZE_RULES:
|
||||
for keyword in rule["keywords"]:
|
||||
if keyword in fname:
|
||||
# Special case logic could go here (e.g. "zombi_otrok" smaller than "zombi")
|
||||
if "otrok" in fname and rule["size"] > 128:
|
||||
return int(rule["size"] * 0.7) # Kids are 70% size
|
||||
return rule["size"]
|
||||
|
||||
return DEFAULT_SIZE
|
||||
|
||||
def intelligent_resize():
|
||||
if not os.path.exists(SOURCE_DIR):
|
||||
print(f"Directory not found: {SOURCE_DIR}")
|
||||
return
|
||||
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError:
|
||||
print("PIL/Pillow not found. Please pip install Pillow.")
|
||||
return
|
||||
|
||||
files = [f for f in os.listdir(SOURCE_DIR) if f.lower().endswith('.png')]
|
||||
if not files:
|
||||
print("No PNG files found.")
|
||||
return
|
||||
|
||||
print(f"Found {len(files)} PNGs. Starting intelligent resizing...")
|
||||
|
||||
for filename in files:
|
||||
filepath = os.path.join(SOURCE_DIR, filename)
|
||||
|
||||
try:
|
||||
target_size = get_target_size(filename)
|
||||
|
||||
with Image.open(filepath) as img:
|
||||
# Calculate new size preserving aspect ratio
|
||||
width, height = img.size
|
||||
aspect_ratio = width / height
|
||||
|
||||
if width > height:
|
||||
new_width = target_size
|
||||
new_height = int(target_size / aspect_ratio)
|
||||
else:
|
||||
new_height = target_size
|
||||
new_width = int(target_size * aspect_ratio)
|
||||
|
||||
# High quality resampling
|
||||
resized_img = img.resize((new_width, new_height), Image.Resampling.LANCZOS)
|
||||
|
||||
# Apply Sharpening (Unsharp Mask) to keep details (piercings!) crisp
|
||||
# Radius 2, Percent 150 is a good standard for "Concept Art" sharpness
|
||||
try:
|
||||
from PIL import ImageFilter
|
||||
resized_img = resized_img.filter(ImageFilter.UnsharpMask(radius=1.5, percent=130, threshold=3))
|
||||
except ImportError:
|
||||
pass # Should be in PIL
|
||||
|
||||
# Save
|
||||
resized_img.save(filepath)
|
||||
print(f"✅ Resized {filename}: {width}x{height} -> {new_width}x{new_height} (Target: {target_size}px)")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error resizing {filename}: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
intelligent_resize()
|
||||
Reference in New Issue
Block a user