64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Created: 2026-06-02
|
|
Updated: 2026-06-02
|
|
Name: verify_icons.py
|
|
Desc: Verify processed icons - check padding is removed and rounded corners applied
|
|
"""
|
|
|
|
from PIL import Image
|
|
import numpy as np
|
|
import os
|
|
|
|
base = '/Users/wushu/Documents/trae_projects/project/xianyan/assets/templates/resized'
|
|
backup_dir = os.path.join(base, 'backup_original')
|
|
|
|
files = sorted([f for f in os.listdir(base) if f.lower().endswith('.png')])
|
|
|
|
print("=" * 70)
|
|
print(f"{'File':<25} {'Size':>8} {'Before Padding':>20} {'After Padding':>20}")
|
|
print("=" * 70)
|
|
|
|
for f in files:
|
|
# Processed image
|
|
path = os.path.join(base, f)
|
|
img = Image.open(path)
|
|
arr = np.array(img)
|
|
h, w = arr.shape[:2]
|
|
|
|
if arr.shape[2] == 4:
|
|
alpha = arr[:, :, 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]]
|
|
after_pad = f"T={rmin} B={h-1-rmax} L={cmin} R={w-1-cmax}"
|
|
else:
|
|
after_pad = "N/A"
|
|
|
|
# Original image
|
|
backup_path = os.path.join(backup_dir, f)
|
|
if os.path.exists(backup_path):
|
|
orig = Image.open(backup_path)
|
|
orig_arr = np.array(orig)
|
|
oh, ow = orig_arr.shape[:2]
|
|
if orig_arr.shape[2] == 4:
|
|
orig_alpha = orig_arr[:, :, 3]
|
|
orig_rows = np.any(orig_alpha > 10, axis=1)
|
|
orig_cols = np.any(orig_alpha > 10, axis=0)
|
|
if orig_rows.any():
|
|
ormin, ormax = np.where(orig_rows)[0][[0, -1]]
|
|
ocmin, ocmax = np.where(orig_cols)[0][[0, -1]]
|
|
before_pad = f"T={ormin} B={oh-1-ormax} L={ocmin} R={ow-1-ocmax}"
|
|
else:
|
|
before_pad = "N/A"
|
|
else:
|
|
before_pad = "no alpha"
|
|
else:
|
|
before_pad = "no backup"
|
|
|
|
print(f"{f:<25} {w:>4}x{h:<4} {before_pad:>20} {after_pad:>20}")
|
|
|
|
print("=" * 70)
|