Files

39 lines
1.3 KiB
Python

# 把 H5 tabbar 的「选中态」图标从旧品牌橙重着色为甄房交互蓝
# 图标为单色 + alpha 通道,按 alpha 保留、RGB 整体替换即可无损改色
# 用法: python _design-test/recolor-tabbar.py (预演)
# python _design-test/recolor-tabbar.py --write (真写)
import os, sys, collections
from PIL import Image
D = r'e:\KF_7\ZhenOS-ZF\zhenfang-uni\src\static\tabbar'
TARGET = (0x00, 0x70, 0xF2) # #0070F2 甄房交互蓝
WRITE = '--write' in sys.argv
def dominant(im):
c = collections.Counter()
for px in im.getdata():
if px[3] > 200:
c[px[:3]] += 1
return c.most_common(1)[0][0] if c else None
for f in sorted(os.listdir(D)):
if not f.endswith('.png') or '_blue' not in f:
continue
p = os.path.join(D, f)
im = Image.open(p).convert('RGBA')
before = dominant(im)
if before == TARGET:
print(' %-22s 已是目标色,跳过' % f)
continue
px = im.load()
for y in range(im.height):
for x in range(im.width):
r, g, b, a = px[x, y]
px[x, y] = (TARGET[0], TARGET[1], TARGET[2], a)
after = dominant(im)
print(' %-22s #%02X%02X%02X -> #%02X%02X%02X' % (f, *before, *after))
if WRITE:
im.save(p)
print('\n' + ('已写入' if WRITE else '预演,未写入(加 --write 生效)'))