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()
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bmtext-0.0.2.tar.gz
.
File metadata
- Download URL: bmtext-0.0.2.tar.gz
- Upload date:
- Size: 44.6 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 141a4dd59a5c4d08ad3960ccb4ac8d044225ab0c24505ab99d79ec67eca3ff01 |
|
MD5 | 0eae10a2c909cfcda7fd228bbdb8ae2b |
|
BLAKE2b-256 | 0b1118410ed9172d33b2044dc6bc156e6e4a5c8da7bbab04bf55f1ca6226fad3 |
File details
Details for the file bmtext-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: bmtext-0.0.2-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31638429c7c5c0c333fc04b08cd08d48eec102d2c41a7a733b7898737af32913 |
|
MD5 | f0f9cbf40ec742a1d6d259aa3c807d5b |
|
BLAKE2b-256 | 422d27c490418c44b5729750e0683e6b137ba8854fa5bcfae81566cd04ee4b7c |