Files
novafarma/scripts/resize_assets.py

49 lines
1.4 KiB
Python

import cv2
import os
# Define target widths for assets
TARGETS = {
'assets/DEMO_FAZA1/UI/badge_purchase.png': 512,
'assets/DEMO_FAZA1/UI/health_critical.png': 512,
'assets/DEMO_FAZA1/VFX/toxic_fog.png': 512,
'assets/DEMO_FAZA1/Environment/obstacle_thorns.png': 256,
'assets/DEMO_FAZA1/Structures/foundation_concrete.png': 512,
'assets/DEMO_FAZA1/Items/hay_drop_0.png': 128
}
def resize_image(path, target_width):
if not os.path.exists(path):
print(f"Skipping {path}, file not found.")
return
img = cv2.imread(path, cv2.IMREAD_UNCHANGED)
if img is None:
print(f"Error loading {path}")
return
h, w = img.shape[:2]
# Check if resize is needed
if w <= target_width:
print(f"{path} is already {w}px (Target: {target_width}px). Skipping resize.")
return
# Calculate new height to maintain aspect ratio
ratio = target_width / w
new_h = int(h * ratio)
resized = cv2.resize(img, (target_width, new_h), interpolation=cv2.INTER_AREA)
cv2.imwrite(path, resized)
print(f"Resized {path}: {w}x{h} -> {target_width}x{new_h}")
if __name__ == "__main__":
base_path = os.getcwd()
print("Starting Resize Job...")
for rel_path, width in TARGETS.items():
full_path = os.path.join(base_path, rel_path)
resize_image(full_path, width)
print("Resize Job Complete.")