Giter VIP home page Giter VIP logo

bmtext's Introduction

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]

bmtext's People

Contributors

judy2k avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.