import os import sys import subprocess from PIL import Image # Import skin conversion logic from convert_skin import convert_skin_64x32_to_64x64 def main(): skins_dir = "skins" control_imgs_dir = "control_imgs" if not os.path.exists(skins_dir): print(f"Error: Skins directory '{skins_dir}' does not exist.") sys.exit(1) os.makedirs(control_imgs_dir, exist_ok=True) # List all PNG files in skins skin_files = [f for f in os.listdir(skins_dir) if f.lower().endswith(".png")] skin_files.sort() print(f"[*] Found {len(skin_files)} skin files in {skins_dir}.") # 1. Pre-repair pass: check and convert all legacy 64x32 skins in the candidate directory print("[*] Running pre-repair check on all skin files...") for skin_file in skin_files: skin_path = os.path.join(skins_dir, skin_file) try: with Image.open(skin_path) as img: width, height = img.size if (width, height) == (64, 32): print(f"[*] Pre-repair: Detected legacy 64x32 skin format for {skin_file}. Auto-converting to 64x64...") convert_skin_64x32_to_64x64(skin_path, skin_path) except Exception as e: print(f"[!] Pre-repair: Error checking skin size for {skin_file}: {e}") skipped = 0 processed = 0 for skin_file in skin_files: skin_path = os.path.join(skins_dir, skin_file) output_path = os.path.join(control_imgs_dir, skin_file) # Check if the output control image already exists if os.path.exists(output_path): skipped += 1 continue print("="*60) print(f"[*] Processing: {skin_file}") # Verify skin size (should be 64x64 after pre-repair) try: with Image.open(skin_path) as img: if img.size != (64, 64): print(f"[!] Warning: Skin '{skin_file}' has unexpected dimensions {img.size}. Skipping.") continue except Exception as e: print(f"[!] Error verifying skin size: {e}") continue # Invoke gpt_skin2real.py using subprocess cmd = [sys.executable, "gpt_skin2real.py", skin_path, "-o", output_path] print(f"[*] Running command: {' '.join(cmd)}") try: # We run the command and check for success. If it fails, we output the error but continue to other skins. subprocess.run(cmd, check=True) print(f"[+] Completed: {skin_file} -> {output_path}") processed += 1 except subprocess.CalledProcessError as e: print(f"[!] Command failed for {skin_file}: {e}") except Exception as e: print(f"[!] Error running pipeline for {skin_file}: {e}") print("="*60) print(f"[*] Batch run completed. Processed: {processed}, Skipped (Already existed): {skipped}.") if __name__ == "__main__": main()