from PIL import Image, ImageDraw, ImageFont, ImageChops from pathlib import Path R=Path(r'C:\projects\wheel\models\switch_2020_concept') def font(s): return ImageFont.truetype(r'C:\Windows\Fonts\msyh.ttc',s) def crop(name): im=Image.open(R/name).convert('RGB'); bg=Image.new('RGB',im.size,'white');d=ImageChops.difference(im,bg).convert('L').point(lambda p:255 if p>15 else 0);bb=d.getbbox();return im.crop(bb) if bb else im def paste_fit(can,im,box): w,h=box[2]-box[0],box[3]-box[1]; im.thumbnail((w,h));can.paste(im,(box[0]+(w-im.width)//2,box[1]+(h-im.height)//2)) out=Image.new('RGB',(1900,1400),'#f4f7fb');d=ImageDraw.Draw(out) d.text((55,26),'灯光开关:横向 2020 与长角码装配示意',font=font(42),fill='#1c2c40') d.text((58,88),'A 比轴心低 35 mm;B 低 22 mm;孔距 85 mm。两孔左右对称仅为示意假设。',font=font(23),fill='#3c526b') for x1,x2 in [(35,920),(950,1865)]: d.rounded_rectangle((x1,135,x2,915),radius=16,fill='white',outline='#d5dce5',width=2) d.text((55,149),'现有整机中的位置',font=font(24),fill='#25384d');d.text((970,149),'沿轴线观察(A 左、B 右)',font=font(24),fill='#25384d') paste_fit(out,crop('focus.png'),(55,195,900,890));paste_fit(out,crop('switch_front.png'),(970,200,1845,840)) d.rounded_rectangle((35,945,1865,1360),radius=16,fill='white',outline='#d5dce5',width=2) d.text((60,967),'当前检查:未能确认开关实物无干涉',font=font(28),fill='#a12e1e') lines=[ '橙色:开关长角码;红色:横梁与纵梁连接角码;绿色:开关估计包络,并非实物外形。', '新增 2020 横梁与绿色估计包络相交;角码也进入包络。真实开关下缘与安装耳尚未建模。', '两角码为避开轴承板角码,各偏移约 0.75 mm;与原角码仅约 0.25 mm 净距。', 'A 孔中心与 2020 顶面齐平,螺丝、垫片及安装耳的真实轴向间隙仍须核对。', '型材 T 槽与实际紧固件未完整建模;此图用于布置讨论,不能证明可装配。'] for i,line in enumerate(lines):d.text((60,1020+60*i),line,font=font(22),fill='#31485e') out.save(R/'开关2020横梁_装配干涉示意.png')