Skip to main content

BDF (Glyph Bitmap Distribution Format) Bitmap Font File Parser in Python

Project description

BDF Parser

PyPI package Actions Status codecov License

BDF (Glyph Bitmap Distribution; Wikipedia; Spec) format bitmap font file parser library in Python. It has Font, Glyph and Bitmap classes providing more than 30 enriched API methods of parsing BDF fonts, getting their meta information, rendering text in any writing direction, adding special effects and manipulating bitmap images. It works seamlessly with PIL / Pillow and NumPy.

Below I'll show you some quick examples, but it is still strongly recommended you go to BDF Parser Python Library's official website to read the detailed documentation / tutorials / API reference.

Install bdfparser library with pip:

pip install bdfparser

Then:

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")

You probably understand what I did in these examples. Whether you do or not, go to bdfparser's documentation website.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bdfparser-2.0.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

bdfparser-2.0.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file bdfparser-2.0.0.tar.gz.

File metadata

  • Download URL: bdfparser-2.0.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1

File hashes

Hashes for bdfparser-2.0.0.tar.gz
Algorithm Hash digest
SHA256 b613a8aeebe2a414c586bc5e087f5fe1c6b5b4ad5b068d3612800efe6dff3837
MD5 df613aadb49268f26295e383c5d6617e
BLAKE2b-256 430ffa4631ac9d5b85660969e44841c01e7705e9db37858a1b10a971a73173cd

See more details on using hashes here.

File details

Details for the file bdfparser-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: bdfparser-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1

File hashes

Hashes for bdfparser-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2b3871e82d09b57a97812ca6bf63a4ba5a55c407ac0929386bca3797614f067
MD5 152eb3594f76063b223687eb67bc442d
BLAKE2b-256 37474a71be61854aa3a2c3672347f7374cdf6d3807a759419499f8d1ecd6b119

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page