BitmapFont Creator
A command-line tool to create bitmap fonts for Phaser games.
Features
- Merge multiple character images into a single texture atlas (PNG)
- Support for extracting frames from sprite sheets
- Character padding support to prevent texture bleeding
- Generate Phaser BitmapText compatible XML font files
- Structured JSON output for programmatic processing
Installation
From Source
The compiled binary will be at target/release/bitmapfont-creator.
From Crates.io
Usage
Basic Command
Command Line Arguments
| Argument | Short | Description | Default |
|---|---|---|---|
--config |
-c |
JSON configuration file path | - |
--stdin |
Read configuration from stdin | false | |
--output |
-o |
Output directory | Current directory |
--font-name |
-f |
Font name | "font" |
--max-size |
Maximum atlas size | 4096 | |
--json |
Output result in JSON format | false | |
--verbose |
-v |
Verbose output mode | false |
Configuration File Format
Basic Format
Extracting Frames from Sprite Sheet
Configuration Fields
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
path |
string | Yes | - | Image file path |
frame |
object | No | - | Sprite sheet frame definition |
frame.x |
number | Yes* | - | Frame X coordinate in sprite sheet |
frame.y |
number | Yes* | - | Frame Y coordinate in sprite sheet |
frame.w |
number | Yes* | - | Frame width |
frame.h |
number | Yes* | - | Frame height |
padding |
number | No | 4 | Character spacing (prevents texture bleeding) |
font_name |
string | No | "font" | Font name |
output_dir |
string | No | "." | Output directory |
* Required when using frame
Output Files
The tool generates two files:
{font-name}.png- Texture atlas containing all characters{font-name}.xml- Phaser BitmapText compatible font description file
XML Format
The generated XML file follows the AngelCode BMFont format:
Character Attributes
| Attribute | Description |
|---|---|
x, y |
Character position in atlas |
width, height |
Character original dimensions |
xoffset, yoffset |
Rendering offset (always 0) |
xadvance |
Horizontal advance distance (character width only, no padding) |
Using with Phaser
// Preload
// Create text
Reading from Stdin
Useful for programmatic invocation:
| \
JSON Output Format
Use --json flag for structured output:
Success Response
Error Response
Error Types
| Error Type | Description |
|---|---|
ConfigParse |
JSON configuration parsing failed |
ImageLoad |
Image loading failed |
Packing |
Atlas packing failed (insufficient space) |
Io |
Filesystem error |
XmlGeneration |
XML generation error |
Tech Stack
- Rust - Systems programming language
- image - Image processing
- serde/serde_json - JSON serialization
- clap - Command line argument parsing
- rectangle-pack - Rectangle packing algorithm
License
This project is licensed under the MIT License.