braille-image
v1.0.1
Published
Convert images to Unicode braille text art
Downloads
291
Maintainers
Readme
braille-image
Convert images to Unicode braille text art.
Install
npm i braille-imageCLI
npx braille-image <input> [options]| Option | Description |
|--------|-------------|
| -w, --width <cells> | Output width in braille cells (default: auto) |
| --height <cells> | Output height in braille cells (default: auto) |
| -t, --threshold <n> | Brightness threshold 0–255 (default: 128) |
| -i, --invert | Invert luminance before thresholding |
| -h, --help | Show usage |
Examples:
# Auto-sized output
npx braille-image photo.jpg
# Fixed 40-cell wide output
npx braille-image photo.jpg --width 40
# Inverted with custom threshold
npx braille-image photo.jpg --invert --threshold 200Library API
import { imageToBraille } from 'braille-image';
const art = await imageToBraille('./photo.jpg', {
width: 40,
invert: true,
});
console.log(art);imageToBraille(input, options?)
| Param | Type | Description |
|-------|------|-------------|
| input | string \| Buffer \| Uint8Array | File path or image buffer |
| options.threshold | number (0–255) | Brightness cutoff. Default: 128 |
| options.width | number | Target width in braille cells |
| options.height | number | Target height in braille cells |
| options.invert | boolean | Invert luminance. Default: false |
Returns: Promise<string> — braille text with \n-separated rows.
Throws: TypeError on invalid options, Error on image processing
failures.
How it works
Grayscale — the input image is converted to single-channel luminance via sharp.
Resize — if
width/heightare specified, the image is scaled to(width × 2) × (height × 4)pixels so each braille cell maps to exactly one 4×2 pixel block.Threshold — each pixel is compared against the
thresholdvalue. Brighter pixels are "raised dots"; darker pixels are left empty.Braille encoding — every 4×2 block is packed into one Unicode braille character using the standard dot layout:
Physical Bit 1 . 4 0 . 3 2 . 5 1 . 4 3 . 6 2 . 5 7 . 8 6 . 7
Development
This project was built collaboratively with Reasonix Code.
Quick start
git clone https://github.com/PuppyOne/braille-image.git
cd braille-image
npm i
npm run build
npm testStack
| Layer | Tool | |-------|------| | Runtime | Node.js ≥ 18, ESM | | Image processing | sharp | | Build | tsdown | | Test | vitest | | Language | TypeScript 6 |
License
Apache-2.0
