81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Harvest and resize all PNG assets from mrtva_dolina collection
|
|
Resizes to 40% and saves to ZETEV_ASSETS_CLEAN on Desktop
|
|
"""
|
|
|
|
from pathlib import Path
|
|
from PIL import Image
|
|
from collections import defaultdict
|
|
import shutil
|
|
|
|
# Paths
|
|
SOURCE_DIR = Path("/Users/davidkotnik/Desktop/novafarma/mrtva_dolina")
|
|
OUTPUT_DIR = Path("/Users/davidkotnik/Desktop/ZETEV_ASSETS_CLEAN")
|
|
|
|
# Create output directory
|
|
OUTPUT_DIR.mkdir(exist_ok=True)
|
|
|
|
# Track duplicate names
|
|
name_counter = defaultdict(int)
|
|
|
|
def resize_image(input_path, output_path, scale=0.4):
|
|
"""Resize image to scale (default 40%)"""
|
|
try:
|
|
img = Image.open(input_path)
|
|
new_width = int(img.width * scale)
|
|
new_height = int(img.height * scale)
|
|
resized = img.resize((new_width, new_height), Image.LANCZOS)
|
|
resized.save(output_path)
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ Error processing {input_path.name}: {e}")
|
|
return False
|
|
|
|
def get_unique_filename(base_name):
|
|
"""Generate unique filename if duplicates exist"""
|
|
name_counter[base_name] += 1
|
|
|
|
if name_counter[base_name] == 1:
|
|
return base_name
|
|
else:
|
|
# Add number before extension: tree.png -> tree_2.png
|
|
stem = Path(base_name).stem
|
|
suffix = Path(base_name).suffix
|
|
return f"{stem}_{name_counter[base_name]}{suffix}"
|
|
|
|
print("🎨 HARVESTING AND RESIZING ASSETS...\n")
|
|
print(f"Source: {SOURCE_DIR}")
|
|
print(f"Output: {OUTPUT_DIR}")
|
|
print(f"Scale: 40%\n")
|
|
|
|
# Find all PNG files
|
|
png_files = list(SOURCE_DIR.rglob("*.png"))
|
|
total = len(png_files)
|
|
|
|
print(f"Found {total} PNG files\n")
|
|
|
|
processed = 0
|
|
skipped = 0
|
|
|
|
for png_file in png_files:
|
|
# Get unique filename
|
|
unique_name = get_unique_filename(png_file.name)
|
|
output_path = OUTPUT_DIR / unique_name
|
|
|
|
# Resize and save
|
|
if resize_image(png_file, output_path):
|
|
processed += 1
|
|
if processed % 100 == 0:
|
|
print(f"✓ Processed {processed}/{total}...")
|
|
else:
|
|
skipped += 1
|
|
|
|
print(f"\n{'='*50}")
|
|
print(f"✅ DONE!")
|
|
print(f"{'='*50}")
|
|
print(f"✓ Processed: {processed}")
|
|
print(f"⚠ Skipped: {skipped}")
|
|
print(f"📂 Output: {OUTPUT_DIR}")
|
|
print(f"\nAll resized assets are in ZETEV_ASSETS_CLEAN folder on Desktop!")
|