BDF (Glyphe Bitmap Distribution; Wikipedia; Spec) Format Bitmap -Schriftart Datei Parser Library in Python. Es verfügt über Font , Glyph und Bitmap -Klassen, die mehr als 30 kettenfähige API -Methoden zur Analyse von BDF -Schriftarten, zum Erhalten ihrer Meta -Informationen, zum Rendern von Text in jede Schreibrichtung, das Hinzufügen von Spezialeffekten und das Manipulieren von Bitmap -Bildern bieten. Es funktioniert nahtlos mit Pil / Kissen und Numpy und verfügt über detaillierte Dokumentation / Tutorials / API -Referenz.
BDF Parser TypeScript (JavaScript) Bibliothek (Dokumentation; Github -Seite; NPM -Seite; npm i bdfparser ) ist ein Port der BDF -Parser -Python -Bibliothek (Dokumentation; Github -Seite; PYPI -Seite; pip install bdfparser ). Beide werden von Tom Chen und unter der MIT -Lizenz geschrieben.
Die Bibliothek BDF Parser Typecript (JavaScript) verfügt über eine Live -Demo und einen Live -Editor, den Sie ausprobieren können.
Im Folgenden zeige ich Ihnen einige kurze Beispiele, aber es wird immer noch dringend empfohlen , die offizielle Website der BDF Parser Python Library zu besuchen, um die detaillierte Dokumentation / Tutorials / API -Referenz zu lesen .
Installieren Sie die BDFParser -Python -Bibliothek mit PIP:
pip install bdfparserDann:
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" )Sie verstehen wahrscheinlich, was ich in diesen Beispielen getan habe. Unabhängig davon, ob Sie dies tun oder nicht, besuchen Sie die Dokumentations -Website von BDFParser .