Q: How do I convert a font into a sprite sheet?
A: fontknife convert
Goal | End Result | Command |
---|---|---|
Rasterize a font's ASCII glyphs | fontknife convert supported.font spritesheet.png |
|
Generate filler assets | fontknife convert -P 48 -G "💪😎" NotoEmoji-Regular.ttf arm_cool.png |
For more detailed explanations, see Practical Examples.
If you only want to convert fonts, follow these steps:
- Have Python 3.8+ installed
- Make sure you've created and activated a virtual environemnt (or use pipx)
- `pip install
- Run
fontknife convert --help
If the last command print help text, you're ready to go! Read it for a descirption of supported arguments.
See CONTRIBUTING.md.
- Read multiple font formats (TTF, BDF, PCF, 1-bit sprite sheets)
- Read arbitrary unicode glyphs from supported fonts, including multi-character emoji
- Export 1-bit sprite sheets to multiple image formats (PNG, BMP, JPG)
- Guess common formats from file extensions
- Simpler than GUI font editors
- Can be used as a library in custom Python scripts
- Assembly code generation (Partial support for Octo)
Please remember:
- This is alpha quality software, so there will be bugs and breaking changes
- The Future Features section lists known areas for improvements
- The project accepts pull requests
- It helps developers iterate faster.
- A refactor of an abandoned projected turned into something else.
Scenario: You need filler assets for a farming game, ASAP.
Solution:
-
Download an appropriately licensed emoji font, such as Noto Emoji,
-
Run the following command
fontknife convert -P 48 -G "🌽🍇🍎🍏🫐🍓🍒🍐🍅🥕🥔🥒🍑🥑🧅🍈" NotoEmoji-Regular.ttf fruits_and_veggies.png
-
Double check & color the results with your preferred image editor
Note: This feature is mostly broken legacy code inherited from an earlier project.
You can generate a width table and sprite data table as valid Octo source if your font meets the following requirements:
- All glyphs can render as 8px x 8px or smaller
- There are 256 or fewer glyphs in the font
For example, run the following to generate tables of widths and sprite data for Tom Thumb as Octo source:
fontknife emit-code tom-thumb.bdf tom-thumb.8o
The data tables should be usable, but the attached drawing routines are not:
- Their underlying logic is broken
- They predate Octo's idiomatic
:stringmode
macro
Features in this section will be added if:
- A PR is made addressing it
- I have time / interest
The features below are in descending order, from highest to lowest priority:
Feature | Questions / Blockers | Easiest known approach |
---|---|---|
Better documentation | Sphinx + RTD, in progress | |
Fix automatic sheet sizing | ||
Export with transparent background color | Outline detection | Improve cli color parsing, replace #000 default with #0000 |
Add foreground color control | Same as above | |
Export to folder of files per glyph | File naming | Use the unicode code point |
Support for automatically reading TTF glyph tables | Use fonttools to read the TTF table | |
Fix ugly caching behavior | Delete / disable caching entirely | |
Better scaling flags, including downsampling | Recommend imagemagick or image editors | |
Additional font formats (see Future Formats | Time / interest | |
C header code generation | Time / interest | |
Refactor or remove Octo generation | Move it to a downstream project | |
Better interface for glyph subset selection | Good design unclear | Write doc on using fontknife in scripts |
Color TTF support | Pillow has bad support for color TTF | Unknown, help welcome! |
Potential font formats to support: