ttfopensans是一个Python包,出售stevematteson的opensans字体。
ttf-opensans的Python项目详细描述
ttf opensans是一个出售Open Sans font by Steve Matteson的Python包。在
它适用于在不必担心目标系统上的可用性的情况下使用opensans字体系列。在
Open Sans字体系列和此软件包是在Apache License, Version 2.0下授权的。在
安装
可以通过以下命令安装此软件包:
python3 -m pip install -U ttf-opensans
使用
字体是通过TTFFont类的实例提供的。在
您可以直接访问特定的字体样式:
^{pr2}$也可以使用helper函数查找最合适的字体样式:
fromttf_opensansimportopensansmy_font=opensans(font_weight=600,italic=True)
一旦有了所需的字体,就可以访问其上的各种属性:
print(my_font.name)# "OpenSans-SemiBoldItalic"print(my_font.weight)# 600print(my_font.italic)# Trueprint(my_font.path)# pathlib.Path("<...>/site_packages/ttf_opensans/ttf/OpenSans-SemiBoldItalic.ttf")
也可以直接打开字体进行阅读:
withmy_font.open()asfp:font_data=fp.read()
如果使用Python Imaging Library(Pillow),还可以直接获取ImageFont实例:
fromPILimportImage,ImageDraw,ImageFontwithImage.new("RGB",(512,512),(255,255,255))asim:draw=ImageDraw.Draw(im)imagefont=my_font.imagefont(size=48)draw.text(font=imagefont,fill=(0,0,0),xy=(0,0),text="Hello World!")
- 项目
标签: