bdfparser
v2.2.0
bdf(雕刻位图分布; wikipedia; spec)格式格式位图字体文件解析器库中的库。它具有Font , Glyph和Bitmap课程,可提供30多种可链式API方法解析BDF字体,获取其元信息,以任何写作方向渲染文本,添加特殊效果和操纵位图图像。它与PIL / Pillow和Numpy无缝工作,并具有详细的文档 /教程 / API参考。
BDF Parser typeScript(JavaScript)库(文档; GitHub页面; NPM页面; npm i bdfparser )是BDF Parser Python库的端口(文档; github page; github page; pypi page; pip install bdfparser )。两者都是由汤姆·陈(Tom Chen)和麻省理工学院许可证(MIT许可证)撰写的。
BDF解析器打字稿(JavaScript)库具有您可以尝试的实时演示和编辑器。
下面我将向您展示一些快速示例,但仍然强烈建议您访问BDF Parser Python Library的官方网站,以阅读详细的文档 /教程 / API参考。
使用PIP安装BDFPARSER PYTHON库:
pip install bdfparser然后:
from bdfparser import Font
font = Font ( 'tests/fonts/unifont-13.0.04.bdf' )
print ( f"This font's global size is "
f" { font . headers [ 'fbbx' ] } x { font . headers [ 'fbby' ] } (pixel), "
f"it contains { len ( font ) } glyphs." )
# =================================
ac = font . glyph ( "a" ). draw (). crop ( 6 , 8 , 1 , 2 ). concat (
font . glyph ( "c" ). draw (). crop ( 6 , 8 , 1 , 2 )
). shadow ()
ac_8x8 = ac * 8
from PIL import Image
im_ac = Image . frombytes ( 'RGBA' ,
( ac_8x8 . width (), ac_8x8 . height ()),
ac_8x8 . tobytes ( 'RGBA' ))
im_ac . save ( "ac.png" , "PNG" )
# =================================
hello = font . draw ( 'Hello!' , direction = 'rl' ). glow ()
print ( hello )
import numpy
import matplotlib . pyplot as plt
nparr = numpy . array ( hello . todata ( 2 ))
plt . imshow ( nparr , 'Blues' )
plt . show ()
# =================================
font_preview = font . drawall ()
im_ac = Image . frombytes ( '1' ,
( font_preview . width (), font_preview . height ()),
font_preview . tobytes ( '1' ))
im_ac . save ( "font_preview.png" , "PNG" )您可能了解我在这些示例中所做的一切。无论您是否这样做,都可以访问BDFPARSER的文档网站。