code.pablomurad.com

htmlansi

Converts images to CP437 ANSI art, as HTML or .ans

git clone https://code.pablomurad.com/htmlansi.git

Recent commits

  1. b05dc14
    Initial commit
    

Full log →

Readme

htmlansi

Convert images to CP437 ANSI art (HTML or .ans).

Requires Node.js >= 20.

Build

npm install
npm run build

Usage

node dist/cli.js <image> -o out.html
node dist/cli.js <image> -f ans -c ansi256 -o out.ans
node dist/cli.js <image> --preview
node dist/cli.js --in ./in --out ./out

Options

-f, --format     html | ans                        (default html)
-m, --mode       glyph | half-block | braille       (default glyph)
    --glyphs     safe | full                        (default safe)
-w, --width      columns                            (default 80)
    --height     rows
-c, --colors     ansi16 | ansi256 | truecolor       (default ansi256)
-d, --dither     none | floyd-steinberg | atkinson  (default none)
    --bg         #rrggbb or r,g,b                   (default #000000)
    --max-width  n                                  (default 200)
    --no-clamp
    --brightness --contrast --gamma --saturation
    --invert
    --preview

Modes

glyph        coverage matching over a CP437 glyph set (default)
half-block   two vertical pixels per cell
braille      2x4 dots per cell

Use -c truecolor for smooth gradients; ansi16/ansi256 band. The default glyph set (safe) keeps rows aligned in any monospace font; –glyphs full adds eighth-blocks and quadrants (needs a font that renders them monospaced).

Library

import { convert, convertToFormat } from 'htmlansi';

const result = await convert('img.png', { mode: 'glyph', width: 100 });
const html   = await convertToFormat('img.png', 'html');

See docs/guide.md and docs/algorithms.md for details.

MIT - runv.sh - https://runv.sh