Files
Neo-ZQYY/scripts/ops/radius_ab_compare.py

72 lines
2.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
borderRadius A/B 对比拼接脚本
拼接三张已有截图为一张对比图H5 baseline | A: ×2 | B: ×0.875
"""
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent
OUT_DIR = PROJECT_ROOT / "export" / "screenshots" / "radius_compare"
def create_comparison():
h5_path = OUT_DIR / "h5_baseline.png"
mp_a_path = OUT_DIR / "mp_a_x2.png"
mp_b_path = OUT_DIR / "mp_b_875.png"
for p in [h5_path, mp_a_path, mp_b_path]:
if not p.exists():
raise FileNotFoundError(f"缺少截图: {p}")
h5 = Image.open(h5_path)
mp_a = Image.open(mp_a_path)
mp_b = Image.open(mp_b_path)
# 统一到相同高度(取最小高度)
target_h = min(h5.height, mp_a.height, mp_b.height)
def resize_to_h(img, th):
ratio = th / img.height
return img.resize((int(img.width * ratio), th), Image.LANCZOS)
h5 = resize_to_h(h5, target_h)
mp_a = resize_to_h(mp_a, target_h)
mp_b = resize_to_h(mp_b, target_h)
label_h = 80
gap = 30
total_w = h5.width + mp_a.width + mp_b.width + gap * 2
total_h = target_h + label_h
canvas = Image.new("RGB", (total_w, total_h), (255, 255, 255))
draw = ImageDraw.Draw(canvas)
# 字体
try:
font = ImageFont.truetype("msyh.ttc", 40)
except Exception:
try:
font = ImageFont.truetype("arial.ttf", 40)
except Exception:
font = ImageFont.load_default()
labels_and_x = [
("H5 原型 (baseline)", 0),
("A: ×2 圆角 (当前)", h5.width + gap),
("B: ×2×0.875 圆角", h5.width + gap + mp_a.width + gap),
]
images = [h5, mp_a, mp_b]
for i, (label, x) in enumerate(labels_and_x):
draw.text((x + 10, 15), label, fill=(0, 0, 0), font=font)
canvas.paste(images[i], (x, label_h))
out_path = OUT_DIR / "comparison_abc.png"
canvas.save(str(out_path), quality=95)
print(f"[Done] 对比图: {out_path}")
print(f" 尺寸: {total_w}x{total_h}")
return out_path
if __name__ == "__main__":
create_comparison()