BDF (Distribusi Bitmap Glyph; Wikipedia; Spec) Format Bitmap Font File Parser Library di Python. Ini memiliki kelas Font , Glyph dan Bitmap yang menyediakan lebih dari 30 metode API rantai untuk parsing font BDF, mendapatkan informasi meta mereka, memberikan teks ke arah penulisan apa pun, menambahkan efek khusus dan memanipulasi gambar bitmap. Ini bekerja dengan mulus dengan PIL / bantal dan numpy, dan memiliki dokumentasi / tutorial / referensi API yang terperinci.
Perpustakaan BDF Parser TypeScript (JavaScript) (Dokumentasi; Halaman GitHub; Halaman NPM; npm i bdfparser ) adalah port BDF Parser Python Library (dokumentasi; halaman GitHub; halaman PYPI; pip install bdfparser ). Keduanya ditulis oleh Tom Chen dan di bawah lisensi MIT.
Perpustakaan BDF Parser TypeScript (JavaScript) memiliki demo & editor langsung yang dapat Anda coba.
Di bawah ini saya akan menunjukkan kepada Anda beberapa contoh cepat, tetapi masih sangat disarankan agar Anda pergi ke situs web resmi BDF Parser Python Library untuk membaca dokumentasi terperinci / referensi Tutorial / API .
Instal Perpustakaan BDFParser Python dengan PIP:
pip install bdfparserKemudian:
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" )Anda mungkin mengerti apa yang saya lakukan dalam contoh -contoh ini. Apakah Anda melakukannya atau tidak, buka situs web dokumentasi BDFParser .