76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
|
|
import os
|
|
from PIL import Image
|
|
|
|
ROOT = "assets/slike"
|
|
|
|
RULES = {
|
|
"teren": 512,
|
|
"liki": 256,
|
|
"animations": 128,
|
|
"zombiji": 128,
|
|
"predmeti": 64
|
|
}
|
|
DEFAULT_SIZE = 512 # For References and others
|
|
|
|
def universal_resize():
|
|
print("🚀 STARTING UNIVERSAL RECURSIVE RESIZER (DEMO, PHASES, REFS)...")
|
|
|
|
total_resized = 0
|
|
|
|
for root, dirs, files in os.walk(ROOT):
|
|
# Determine strict size based on path context
|
|
# Check against rules
|
|
target_size = DEFAULT_SIZE # Default for refs/others
|
|
|
|
path_lower = root.lower()
|
|
|
|
# Priority order?
|
|
# what if path has both liki and animation? (unlikely)
|
|
|
|
# Match rules
|
|
matched = False
|
|
for key, size in RULES.items():
|
|
if key in path_lower:
|
|
target_size = size
|
|
matched = True
|
|
break
|
|
|
|
# If no match, check if it's references (stay 512 default) or DEMO root (might be mixed)
|
|
# If it's pure DEMO root (not in subfolder), default apply.
|
|
|
|
for file in files:
|
|
if file.lower().endswith(('.png', '.jpg', '.jpeg')):
|
|
filepath = os.path.join(root, file)
|
|
|
|
try:
|
|
with Image.open(filepath) as img:
|
|
current_w, current_h = img.size
|
|
|
|
# Only Resize if needed
|
|
# Scale proportionally to fit Square box? Or force Square?
|
|
# User Tables implied Force Square (512x512).
|
|
# Assuming Force Resize to Tuple (size, size)
|
|
|
|
wanted_size = (target_size, target_size)
|
|
|
|
if img.size != wanted_size:
|
|
# print(f"🔧 Resizing {file} ({current_w}x{current_h}) -> {wanted_size} (Context: {matched})")
|
|
img_resized = img.resize(wanted_size, Image.Resampling.LANCZOS)
|
|
img_resized.save(filepath)
|
|
total_resized += 1
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error {file}: {e}")
|
|
|
|
# Verify progress
|
|
# print(f"Scanned {root}")
|
|
|
|
print("="*40)
|
|
print(f"✅ UNIVERSAL RESIZE COMPLETE.")
|
|
print(f"Total Images Adjusted: {total_resized}")
|
|
print("="*40)
|
|
|
|
if __name__ == "__main__":
|
|
universal_resize()
|