69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
import os
|
|
import sys
|
|
|
|
# Dependency Check
|
|
try:
|
|
from PIL import Image, ImageOps
|
|
except ImportError:
|
|
print("❌ Error: Pillow library not found.")
|
|
print("👉 Please run: pip install Pillow")
|
|
sys.exit(1)
|
|
|
|
# Configuration
|
|
# Paths are relative to where the script is run, assuming run from root or automation folder
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
SOURCE_DIR = os.path.join(BASE_DIR, "Raw_Assets")
|
|
OUTPUT_DIR = os.path.join(BASE_DIR, "Ready_Assets")
|
|
|
|
# Target Dimensions (Width, Height)
|
|
ASSETS = {
|
|
"AppIcon": (1024, 1024),
|
|
"logo_header": (300, 80),
|
|
"scanner_frame": (600, 800),
|
|
"empty_library": (800, 800),
|
|
"share_watermark": (400, 100),
|
|
"card_placeholder": (600, 840)
|
|
}
|
|
|
|
def process_assets():
|
|
print(f"📂 Working Directory: {BASE_DIR}")
|
|
|
|
# Create directories if they don't exist
|
|
if not os.path.exists(SOURCE_DIR):
|
|
os.makedirs(SOURCE_DIR)
|
|
print(f"✅ Created source folder: {SOURCE_DIR}")
|
|
print("👉 ACTION REQUIRED: Place your raw AI images here (e.g., 'AppIcon.png') and run this script again.")
|
|
return
|
|
|
|
if not os.path.exists(OUTPUT_DIR):
|
|
os.makedirs(OUTPUT_DIR)
|
|
print(f"✅ Created output folder: {OUTPUT_DIR}")
|
|
|
|
print(f"🚀 Processing images from 'Raw_Assets'...")
|
|
|
|
for name, size in ASSETS.items():
|
|
found = False
|
|
# Check for common image extensions
|
|
for ext in [".png", ".jpg", ".jpeg", ".webp"]:
|
|
source_path = os.path.join(SOURCE_DIR, name + ext)
|
|
if os.path.exists(source_path):
|
|
try:
|
|
img = Image.open(source_path)
|
|
if img.mode != 'RGBA': img = img.convert('RGBA')
|
|
|
|
# Smart Crop & Resize (Center focus)
|
|
processed_img = ImageOps.fit(img, size, method=Image.Resampling.LANCZOS)
|
|
|
|
output_path = os.path.join(OUTPUT_DIR, name + ".png")
|
|
processed_img.save(output_path, "PNG")
|
|
print(f"✅ Generated: {name}.png ({size[0]}x{size[1]})")
|
|
found = True
|
|
break
|
|
except Exception as e:
|
|
print(f"❌ Error processing {name}: {e}")
|
|
|
|
if not found:
|
|
print(f"⚠️ Skipped: {name} (File not found in Raw_Assets)")
|
|
|
|
if __name__ == "__main__":
|
|
process_assets() |