Files
wheel/scripts/compose_kfl_same_flange_125.py

36 lines
2.3 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.
from PIL import Image, ImageChops, ImageDraw, ImageFont
from pathlib import Path
out = Path(r'C:\projects\wheel\models\kfl_same_flange_125')
font_path = r'C:\Windows\Fonts\msyh.ttc'
title = ImageFont.truetype(font_path, 38)
normal = ImageFont.truetype(font_path, 24)
small = ImageFont.truetype(font_path, 21)
im = Image.new('RGB', (1920, 1150), 'white')
d = ImageDraw.Draw(im)
d.text((40, 18), '125 mm 轴与两端相同法兰 · 装配示意', fill='#1a304d', font=title)
d.text((40, 80), '轴 Ø12 × 125 mm;两端法兰底盘 Ø57 × 4 mm,凸台 Ø30 × 20 mm', fill='#52657b', font=normal)
d.rounded_rectangle((40, 123, 1880, 177), radius=8, fill='#fff0eb')
d.text((55, 134), '概念布局:轴承、开关及电机中心螺母未实测,不能证明实物装配通过', fill='#9b2b22', font=normal)
def panel(path, box, rotate=False):
view = Image.open(path).convert('RGB')
if rotate:
view = view.rotate(90, expand=True)
mask = ImageChops.difference(view, Image.new('RGB', view.size, 'white')).convert('L').point(lambda p:255 if p>12 else 0)
bounds = mask.getbbox()
if bounds:
view = view.crop(bounds)
view.thumbnail((box[2]-box[0],box[3]-box[1]))
im.paste(view, (box[0] + (box[2]-box[0]-view.width)//2, box[1] + (box[3]-box[1]-view.height)//2))
d.text((40, 196), '侧视图(电机在左,方向盘侧在右)', font=normal, fill='#243a55')
panel(out / 'side.png', (35, 230, 1885, 740), True)
d.line((40, 760, 1880, 760), fill='#d8e0e9', width=2)
d.text((42, 781), '本次几何示意:两端凸台各插入约 19.5 mm;两端轴面离法兰底盘各约 0.5 mm。', font=small, fill='#243a55')
d.text((42, 825), '电机中心 M3 螺母未建模:轴端可能与螺母干涉,不能据此认为此布局能装。', font=small, fill='#9b2b22')
d.text((42, 869), '绿色:灯光开关 50 mm 包络占位;内部 Ø47 孔是示意,白色回正机构未建模。', font=small, fill='#405b4a')
d.text((42, 913), '轴承凸起、铝板孔、端部键槽及连接五金均待核实;当前轴承到法兰名义间隙约 0.5 mm。', font=small, fill='#46586b')
d.text((42, 957), '125 mm 为用户选择的轴长;法兰/轴的配合、位置和强度仍需实物确认。', font=small, fill='#46586b')
im.save(out / '125mm轴_装配示意.png')