Files
wheel/scripts/compose_crossbar_132.py

15 lines
1.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, ImageDraw, ImageFont
from pathlib import Path
p=Path(r'C:\projects\wheel\models\switch_2020_crossbar132')
im=Image.new('RGB',(2000,1250),'white');d=ImageDraw.Draw(im)
font=ImageFont.truetype(r'C:\Windows\Fonts\msyh.ttc',42); sub=ImageFont.truetype(r'C:\Windows\Fonts\msyh.ttc',26)
d.text((35,20),'灯光开关 2020 横梁:132 mm 下料方案',font=font,fill='#162c44')
d.text((35,88),'横梁置于两根 3030 纵梁上方;两端各突出约 0.38 mm',font=sub,fill='#415a70')
def paste(source,rect):
pic=Image.open(p/source).convert('RGB');bg=Image.new('RGB',pic.size,'white');diff=__import__('PIL.ImageChops',fromlist=['difference']).difference(pic,bg);box=diff.getbbox();pic=pic.crop(box) if box else pic
x0,y0,x1,y1=rect;pic.thumbnail((x1-x0,y1-y0),Image.Resampling.LANCZOS);im.paste(pic,(x0+(x1-x0-pic.width)//2,y0+(y1-y0-pic.height)//2))
paste('assembly.png',(30,175,1000,1120));paste('crossbar_front.png',(1020,240,1980,1030))
d.text((90,130),'整体装配(转向灯为绿色示意包络)',font=sub,fill='#344d62');d.text((1110,180),'开关横梁正视图',font=sub,fill='#344d62')
d.text((80,1150),'注:灯光开关为示意包络;真实安装孔位置、槽型及滑块须在装配时核对。',font=sub,fill='#8a4141')
im.save(p/'132mm横梁_3D装配示意.png')