116 lines
3.5 KiB
Python
116 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Add missing preview versions (256x256) to existing assets.
|
||
This fixes the problem where you have:
|
||
- 2 large files (1024x1024) - too big
|
||
- 2 tiny files (32x32) - can't see them
|
||
Now adds medium preview versions (256x256) that you CAN see!
|
||
"""
|
||
|
||
import os
|
||
from pathlib import Path
|
||
from PIL import Image
|
||
|
||
def add_preview_to_asset(asset_path: Path):
|
||
"""
|
||
For each *_styleA.png or *_styleB.png file:
|
||
- Check if preview version exists
|
||
- Create 256x256 preview if missing
|
||
"""
|
||
|
||
# Skip if not a style file
|
||
if not (asset_path.stem.endswith('_styleA') or asset_path.stem.endswith('_styleB')):
|
||
return False
|
||
|
||
# Skip if already a preview or sprite
|
||
if 'preview' in asset_path.stem or 'sprite' in asset_path.stem or '32x32' in asset_path.stem:
|
||
return False
|
||
|
||
try:
|
||
# Get base name (remove _styleA or _styleB)
|
||
stem = asset_path.stem
|
||
if stem.endswith('_styleA'):
|
||
base_name = stem[:-7]
|
||
style = 'styleA'
|
||
else:
|
||
base_name = stem[:-7]
|
||
style = 'styleB'
|
||
|
||
# Create preview filename
|
||
preview_filename = f"{base_name}_{style}_preview_256x256.png"
|
||
preview_path = asset_path.parent / preview_filename
|
||
|
||
# Skip if preview already exists
|
||
if preview_path.exists():
|
||
print(f" ⏭️ Preview already exists: {preview_filename}")
|
||
return False
|
||
|
||
# Load original
|
||
img = Image.open(asset_path)
|
||
orig_width, orig_height = img.size
|
||
|
||
# Create 256x256 preview
|
||
preview = img.resize((256, 256), Image.Resampling.LANCZOS)
|
||
preview.save(preview_path, 'PNG', optimize=True)
|
||
|
||
print(f" ✅ Created preview: {preview_filename}")
|
||
print(f" From: {asset_path.name} ({orig_width}×{orig_height})")
|
||
|
||
return True
|
||
|
||
except Exception as e:
|
||
print(f" ❌ Error with {asset_path.name}: {e}")
|
||
return False
|
||
|
||
def process_directory(directory: Path):
|
||
"""Process all PNG files in directory and subdirectories"""
|
||
|
||
print(f"\n📂 Processing: {directory}")
|
||
print("=" * 70)
|
||
|
||
# Find all PNG files recursively
|
||
png_files = list(directory.rglob('*.png'))
|
||
|
||
if not png_files:
|
||
print(" No PNG files found")
|
||
return 0
|
||
|
||
count = 0
|
||
for png_file in png_files:
|
||
if add_preview_to_asset(png_file):
|
||
count += 1
|
||
|
||
return count
|
||
|
||
def main():
|
||
print("=" * 70)
|
||
print("🖼️ ADD PREVIEW VERSIONS (256x256) TO EXISTING ASSETS")
|
||
print("=" * 70)
|
||
print("\nThis will create visible preview versions of all assets!")
|
||
print("You'll have:")
|
||
print(" - assetname_styleA.png (1024×1024 original)")
|
||
print(" - assetname_styleA_preview_256x256.png (VISIBLE!)")
|
||
print(" - assetname_styleA_32x32.png (32×32 sprite)")
|
||
print("=" * 70)
|
||
|
||
# Process demo directory
|
||
demo_dir = Path('assets/images/demo')
|
||
total = 0
|
||
|
||
if demo_dir.exists():
|
||
total += process_directory(demo_dir)
|
||
|
||
# Process other directories
|
||
images_dir = Path('assets/images')
|
||
for subdir in images_dir.iterdir():
|
||
if subdir.is_dir() and subdir.name != 'demo':
|
||
total += process_directory(subdir)
|
||
|
||
print("\n" + "=" * 70)
|
||
print(f"✅ COMPLETE! Created {total} preview versions")
|
||
print("=" * 70)
|
||
print("\n💡 Now your files are VISIBLE in file explorer!")
|
||
|
||
if __name__ == "__main__":
|
||
main()
|