This tool converts an image containing Unicode glyphs into Rust-compatible bitmap arrays for use in the img2irc project.
-
Create input files:
- An image file with glyphs rendered horizontally, without gaps. Essentially a cropped screenshot of the rendered characters with no spaces in between.
- A text file listing the same glyphs separated by spaces.
-
Generate JSON bitmap data (
mkbitmap.py). -
Convert JSON to Rust source (
mkrust.py). -
Replace
src/chars.rsinimg2ircwith the generated Rust file and recompile.
Slices an image into bitmaps and outputs JSON.
Arguments:
| Argument | Description |
|---|---|
chars_file |
Text file containing glyphs separated by spaces. |
image_file |
Horizontal image of glyphs (no gaps). |
--icw |
Input character width (pixels). |
--ich |
Input character height (pixels). |
--threshold |
Black/white pixel threshold (0–255). |
--obw |
Output bitmap width. |
--obh |
Output bitmap height. |
--output |
Output JSON filename. |
Example:
./mkbitmap.py chars.txt chars.png --icw 20 --ich 40 --threshold 128 --obw 10 --obh 20 --output chars.jsonConverts JSON bitmap data to Rust source code.
Arguments:
| Argument | Description |
|---|---|
input_json |
JSON file from mkbitmap.py. |
output_rs |
Output Rust source file. |
Example:
./mkrust.py chars.json chars.rsReplace the resulting chars.rs in your img2irc project and recompile.
You can use the included chars.txt and chars.png as an example.