██████╗ ██╗████████╗███╗ ███╗██████╗ ██████╗ ██╗████████╗ ██╔══██╗██║╚══██╔══╝████╗ ████║██╔══██╗██╔══██╗██║╚══██╔══╝ ██████╔╝██║ ██║ ██╔████╔██║███████║██████╔╝██║ ██║ ██╔══██╗██║ ██║ ██║╚██╔╝██║██╔══██║██╔═══╝ ██║ ██║ ██║ ██║██║ ██║ ██║ ╚═╝ ██║██║ ██║██║ ██║ ██║ ██████╔╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
npm install bitmapit
Or include directly in your HTML:
<script type="module">
import { BitmapFontGenerator } from './path/to/bitmapit/index.js';
</script>
import { defaultFont, BitmapFontGenerator } from 'bitmapit';
// Create generator
const generator = new BitmapFontGenerator();
// Define characters
Object.entries(defaultFont).forEach(([char, pattern]) => {
generator.defineCharacter(char, pattern);
});
// Generate text
const bitmap = generator.generateText('HELLO');
console.log(generator.toAscii(bitmap));
const generator = new BitmapFontGenerator({
width: 8, // Character width
height: 8, // Character height
spacing: 1 // Space between characters
});
const generator = new BitmapFontGenerator({
onChar: '█', // Character for filled pixels
offChar: ' ', // Character for empty pixels
color: '#ffffff', // Text color (HTML only)
backgroundColor: '#000000' // Background color (HTML only)
});
Creates a new bitmap font generator instance.
options.width
: Number (default: 8) - Width of each character
options.height
: Number (default: 8) - Height of each character
options.spacing
: Number (default: 1) - Space between characters
options.onChar
: String (default: '█') - Character for filled pixels
options.offChar
: String (default: ' ') - Character for empty pixels
Defines a new character pattern.
generator.defineCharacter('A', [
[0,1,1,1,0],
[1,0,0,0,1],
[1,1,1,1,1],
[1,0,0,0,1],
[1,0,0,0,1]
]);
Generates a bitmap pattern for the given text.
const bitmap = generator.generateText('HELLO');
Converts a bitmap to ASCII art.
const ascii = generator.toAscii(bitmap, {
on: '█',
off: ' '
});
Converts a bitmap to HTML with styling.
const html = generator.toHtml(bitmap, {
color: '#ff0000',
backgroundColor: '#000000',
on: '█',
off: ' '
});
Updates the font dimensions.
generator.setDimensions(10, 10);
Sets the spacing between characters.
generator.setSpacing(2);
const generator = new BitmapFontGenerator();
Object.entries(defaultFont).forEach(([char, pattern]) => {
generator.defineCharacter(char, pattern);
});
const bitmap = generator.generateText('HELLO');
console.log(generator.toAscii(bitmap));
const bitmap = generator.generateText('HELLO');
const html = generator.toHtml(bitmap, {
color: '#ff0000',
backgroundColor: '#000000'
});
document.body.innerHTML = html;
const bitmap = generator.generateText('HELLO');
const ascii = generator.toAscii(bitmap, {
on: '*',
off: '.'
});
generator.setDimensions(12, 12);
generator.setSpacing(2);
const bitmap = generator.generateText('BIG');
The library works in all modern browsers that support ES6 modules.