#!/usr/bin/env python3 """ Created: 2026-06-02 Updated: 2026-06-02 Name: analyze_icons.py Desc: Analyze icon files to understand border/padding situation """ from PIL import Image import numpy as np import os base = '/Users/wushu/Documents/trae_projects/project/xianyan/assets/templates/resized' files = sorted(os.listdir(base)) for f in files[:8]: path = os.path.join(base, f) img = Image.open(path) arr = np.array(img) h, w = arr.shape[:2] print(f"\n=== {f} ({w}x{h}, mode={img.mode}) ===") if arr.shape[2] == 4: alpha = arr[:, :, 3] print(f" Corners alpha: TL={arr[0,0,3]} TR={arr[0,-1,3]} BL={arr[-1,0,3]} BR={arr[-1,-1,3]}") rows = np.any(alpha > 10, axis=1) cols = np.any(alpha > 10, axis=0) if rows.any(): rmin, rmax = np.where(rows)[0][[0, -1]] cmin, cmax = np.where(cols)[0][[0, -1]] print(f" Content: row[{rmin}-{rmax}] col[{cmin}-{cmax}]") print(f" Padding: top={rmin} bottom={h-1-rmax} left={cmin} right={w-1-cmax}") else: print(" No visible content!") else: print(f" No alpha channel (mode={img.mode})")