Files
novafarma/scripts/resize_assets.py
2026-01-20 01:05:17 +01:00

49 lines
1.8 KiB
Python

from PIL import Image
import os
# Configuration
# Configuration
TARGET_DIRS = ["assets/grounds", "assets/maps/tilesets"] # Expanded targets
TARGET_SIZE = (256, 256)
def resize_images():
for target_dir in TARGET_DIRS:
if not os.path.exists(target_dir):
print(f"⚠️ Directory {target_dir} not found. Skipping.")
continue
print(f"📂 Processing directory: {target_dir}...")
files = [f for f in os.listdir(target_dir) if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
for filename in files:
filepath = os.path.join(target_dir, filename)
try:
with Image.open(filepath) as img:
width, height = img.size
# SELECTIVE RESIZE LOGIC
# 1. Must be Square 1024x1024 (Grounds, Props, Trees)
# 2. Or if explicitly in 'grounds' folder and > 256
should_resize = False
if "grounds" in target_dir and width > 256:
should_resize = True
elif width == 1024 and height == 1024:
should_resize = True
if should_resize:
print(f"✨ Resizing {filename} ({width}x{height}) -> {TARGET_SIZE} (Lanczos)")
img_resized = img.resize(TARGET_SIZE, Image.Resampling.LANCZOS)
img_resized.save(filepath)
else:
pass # print(f"Skipping {filename} ({width}x{height}) - Criteria not met")
except Exception as e:
print(f"❌ Error processing {filename}: {e}")
if __name__ == "__main__":
resize_images()