Skip to main content

Render text from BMFont bitmap fonts.

Project description

BMText

Render text with BMFont generated bitmap fonts.

Status: The core of this code is reasonably well tested, but it's at an early stage, it's basically just been thrown up online, and you use it at your own risk.

Why???

I wanted kerning, and I wanted support for a widespread bitmap font format. BMFont is used to generate bitmap fonts from Truetype fonts, and the format it uses seems reasonably well supported.

I have vague plans to extend the format slightly to allow pre-rendered glyphs - so characters could be multi-colored or embossed, for example.

Using it

Install it with:

python -m pip install bmtext

Currently the API matches ImageDraw.text as closely as possible (given the limited feature-set).

from PIL import Image
from bmtext.meta import parse_file
from bmtext.pil import BMText

im = Image.new('RGB', (320, 180), color=(160, 160, 255))
drawer = BMText(im)
font = parse_file("tests/fixtures/raleway-30/raleway-thin-32.fnt")
# FIXME: Overlapping glyphs remove part of previous char.
drawer.text((5, 5), "Antidisestablishmentarianism\nThorough\nSHOUTING!!!\nTomato?", font, fill='blue')
im.show()

Sample of rendered text

To Do

  • FNT Compatibility:
    • Handle binary font metadata formats.
    • Test with multiple pages
    • Multiple channel support
    • Outline support (2-pass rendering)
  • Improve error handling:
    • Malformed fnt files
    • Missing characters from font (replace/error)
  • Features:
    • Allow arrangement of pre-rendered characters (rather than single-color alpha characters).
    • Implement textsize
    • Implement alignment
    • Implement anchor
  • More testing:
    • Test with older versions of pillow
  • Port to Python 3.5+ (remove the walrus operator)

Developing

Run the following to install the project (and dev dependencies) into your active virtualenv:

pip install -e .[dev]

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

bmtext-0.0.1.tar.gz (44.5 kB view details)

Uploaded Source

Built Distribution

bmtext-0.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file bmtext-0.0.1.tar.gz.

File metadata

  • Download URL: bmtext-0.0.1.tar.gz
  • Upload date:
  • Size: 44.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for bmtext-0.0.1.tar.gz
Algorithm Hash digest
SHA256 159930efc1205e76c8bfaa68789726cac81d0478a7bbd1ed2e9c4cb96e8129cb
MD5 91b6bccbcb55c9fb80ad4c0528d5228f
BLAKE2b-256 4b99ed10db7eed8a7972f408ad4f0cd42ad58359d9773db1834090da3ab0cbb6

See more details on using hashes here.

Provenance

File details

Details for the file bmtext-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: bmtext-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for bmtext-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef60dc6286a1754d6a826fea086a96eaa58d1ee8580806e78841455af690f29a
MD5 d7427b8bf7318152103688635ee7954d
BLAKE2b-256 376066b0ae80fd875042c94f403ef7041660241a815eb9ed787f58eb836f9920

See more details on using hashes here.

Provenance

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