{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"mount_file_id":"1lJau6I3T-5TFCyT3fiFqtWoMRINEbl5p","authorship_tag":"ABX9TyP6koKS5z6sL/Rw6hd0qC7z"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"cellView":"form","id":"Sr62-etruB5w"},"outputs":[],"source":["# @title Assemble images into 8x8 grid (5120x5120)\n","# @markdown Path to zip file containing the 1024x1024 images\n","zip_path = \"/content/drive/MyDrive/showc.zip\" # @param {type:\"string\"}\n","\n","import os\n","import zipfile\n","from PIL import Image\n","from pathlib import Path\n","from google.colab import drive\n","\n","# Mount Google Drive\n","drive.mount('/content/drive')\n","\n","# Create folders\n","os.makedirs('/content/extracted', exist_ok=True)\n","os.makedirs('/content/output', exist_ok=True)\n","\n","# Extract zip\n","print(\"Extracting zip...\")\n","with zipfile.ZipFile(zip_path, 'r') as zip_ref:\n"," zip_ref.extractall('/content/extracted')\n","\n","# Get all images\n","image_files = []\n","for ext in ['*.png', '*.jpg', '*.jpeg', '*.webp', '*.bmp']:\n"," image_files.extend(Path('/content/extracted').rglob(ext))\n","\n","image_files = sorted([str(f) for f in image_files])\n","print(f\"Found {len(image_files)} images.\")\n","\n","# Parameters\n","FINAL_SIZE = 5120\n","GRID_SIZE = 8 # 16x16 grid\n","TILE_SIZE = FINAL_SIZE // GRID_SIZE # 320 pixels\n","GRAY = (24, 24, 24) # 181818 hex\n","\n","# Process in batches of 256 images (16×16)\n","batch_size = GRID_SIZE * GRID_SIZE # 256\n","output_files = []\n","\n","for i in range(0, len(image_files), batch_size):\n"," batch = image_files[i:i + batch_size]\n","\n"," # Create blank 5120x5120 canvas\n"," large_img = Image.new('RGB', (FINAL_SIZE, FINAL_SIZE), GRAY)\n","\n"," for idx, img_path in enumerate(batch):\n"," try:\n"," img = Image.open(img_path).convert('RGB')\n"," # Resize to 320x320\n"," img = img.resize((TILE_SIZE, TILE_SIZE), Image.Resampling.LANCZOS)\n","\n"," row = idx // GRID_SIZE\n"," col = idx % GRID_SIZE\n"," x = col * TILE_SIZE\n"," y = row * TILE_SIZE\n","\n"," large_img.paste(img, (x, y))\n"," except Exception as e:\n"," print(f\"Error with {img_path}: {e}\")\n","\n"," # Save the large image\n"," output_path = f\"/content/output/{(i//batch_size)+1:03d}.png\"\n"," large_img.save(output_path, quality=95, optimize=True)\n"," output_files.append(output_path)\n"," print(f\"Saved {output_path} ({len(batch)} tiles)\")\n","\n","# Zip and save to Google Drive\n","output_zip = \"/content/drive/MyDrive/assembled_5120x5120_8x8.zip\"\n","with zipfile.ZipFile(output_zip, 'w', zipfile.ZIP_DEFLATED) as z:\n"," for f in output_files:\n"," z.write(f, os.path.basename(f))\n","\n","print(\"\\n✅ Done!\")\n","print(f\"Created {len(output_files)} images of 5120×5120 (8x8 grid)\")\n","print(f\"Zip saved to Google Drive: {output_zip}\")"]},{"cell_type":"code","execution_count":null,"metadata":{"cellView":"form","id":"q4ANrSGkx638"},"outputs":[],"source":["# @title Assemble images into 16x16 grid (5120x5120)\n","# @markdown Path to zip file containing the 1024x1024 images\n","zip_path = \"/content/drive/MyDrive/showc.zip\" # @param {type:\"string\"}\n","\n","import os\n","import zipfile\n","from PIL import Image\n","from pathlib import Path\n","from google.colab import drive\n","\n","# Mount Google Drive\n","drive.mount('/content/drive')\n","\n","# Create folders\n","os.makedirs('/content/extracted', exist_ok=True)\n","os.makedirs('/content/output', exist_ok=True)\n","\n","# Extract zip\n","print(\"Extracting zip...\")\n","with zipfile.ZipFile(zip_path, 'r') as zip_ref:\n"," zip_ref.extractall('/content/extracted')\n","\n","# Get all images\n","image_files = []\n","for ext in ['*.png', '*.jpg', '*.jpeg', '*.webp', '*.bmp']:\n"," image_files.extend(Path('/content/extracted').rglob(ext))\n","\n","image_files = sorted([str(f) for f in image_files])\n","print(f\"Found {len(image_files)} images.\")\n","\n","# Parameters\n","FINAL_SIZE = 5120\n","GRID_SIZE = 16 # 16x16 grid\n","TILE_SIZE = FINAL_SIZE // GRID_SIZE # 320 pixels\n","GRAY = (24, 24, 24) # 181818 hex\n","\n","# Process in batches of 256 images (16×16)\n","batch_size = GRID_SIZE * GRID_SIZE # 256\n","output_files = []\n","\n","for i in range(0, len(image_files), batch_size):\n"," batch = image_files[i:i + batch_size]\n","\n"," # Create blank 5120x5120 canvas\n"," large_img = Image.new('RGB', (FINAL_SIZE, FINAL_SIZE), GRAY)\n","\n"," for idx, img_path in enumerate(batch):\n"," try:\n"," img = Image.open(img_path).convert('RGB')\n"," # Resize to 320x320\n"," img = img.resize((TILE_SIZE, TILE_SIZE), Image.Resampling.LANCZOS)\n","\n"," row = idx // GRID_SIZE\n"," col = idx % GRID_SIZE\n"," x = col * TILE_SIZE\n"," y = row * TILE_SIZE\n","\n"," large_img.paste(img, (x, y))\n"," except Exception as e:\n"," print(f\"Error with {img_path}: {e}\")\n","\n"," # Save the large image\n"," output_path = f\"/content/output/{(i//batch_size)+1:03d}.png\"\n"," large_img.save(output_path, quality=95, optimize=True)\n"," output_files.append(output_path)\n"," print(f\"Saved {output_path} ({len(batch)} tiles)\")\n","\n","# Zip and save to Google Drive\n","output_zip = \"/content/drive/MyDrive/assembled_5120x5120_16x16.zip\"\n","with zipfile.ZipFile(output_zip, 'w', zipfile.ZIP_DEFLATED) as z:\n"," for f in output_files:\n"," z.write(f, os.path.basename(f))\n","\n","print(\"\\n✅ Done!\")\n","print(f\"Created {len(output_files)} images of 5120×5120 (16×16 grid)\")\n","print(f\"Zip saved to Google Drive: {output_zip}\")"]}]}