ANSI Art to GIF Converter
Convert ANSI art with escape codes to animated GIF images. Supports 256 colors, blink animation, custom fonts, and full GIF89a encoding in-browser.
.ans / .txt file here or click to browse
About
ANSI art encodes visual data through escape sequences defined in ECMA-48 (ISO/IEC 6429). A misinterpreted SGR parameter - say, confusing 38;5;n (256-color foreground) with 48;5;n (background) - renders the entire piece incorrectly. This converter parses raw ANSI text, builds a cell grid of dimensions cols × rows, and rasterizes each cell onto a Canvas at a configurable font size. The resulting pixel buffer is then quantized to ≤ 256 colors via median-cut and encoded into a GIF89a binary stream with LZW compression. No server round-trip occurs. The tool approximates standard VGA terminal rendering assuming a CP437-compatible monospace font and a fixed 80-column width. Blink attributes produce a two-frame animation. Color accuracy depends on your display calibration against the canonical CGA/EGA/VGA palette.
Formulas
The converter rasterizes each ANSI cell onto a bitmap of total size:
where cols defaults to 80 and charWidth, charHeight derive from the rendered font metrics. The GIF89a stream uses LZW variable-length coding. Initial code size:
where paletteSize ≤ 256 is determined by median-cut quantization. Each frame includes a Graphic Control Extension specifying disposal method and delay:
where interval is the user-configured millisecond delay between frames. For blink animation, two frames alternate: one with blinking characters visible, one with them hidden (background-only). The Netscape Application Extension block sets loop count to 0 (infinite).
Reference Data
| SGR Code | Effect | Typical Rendering |
|---|---|---|
| 0 | Reset / Normal | All attributes off |
| 1 | Bold / Bright | Increased intensity or bright color variant |
| 5 | Slow Blink | Toggles visibility at < 150 bpm |
| 7 | Reverse Video | Swap foreground and background |
| 30 - 37 | Set foreground (standard) | Black, Red, Green, Yellow, Blue, Magenta, Cyan, White |
| 40 - 47 | Set background (standard) | Same 8 colors as background |
| 90 - 97 | Set foreground (bright) | Bright variants of standard 8 |
| 100 - 107 | Set background (bright) | Bright variants as background |
| 38;5;n | 256-color foreground | n ∈ [0, 255] |
| 48;5;n | 256-color background | n ∈ [0, 255] |
| 38;2;r;g;b | 24-bit truecolor foreground | Direct RGB specification |
| 48;2;r;g;b | 24-bit truecolor background | Direct RGB specification |
| ESC[nA | Cursor Up | Move cursor up n rows |
| ESC[nB | Cursor Down | Move cursor down n rows |
| ESC[nC | Cursor Forward | Move cursor right n columns |
| ESC[nD | Cursor Back | Move cursor left n columns |
| ESC[r;cH | Cursor Position | Move to row r, column c |
| ESC[2J | Erase Display | Clear entire screen |
| ESC[K | Erase in Line | Clear from cursor to end of line |
| GIF89a LZW | Min code size | Palette bits, typically 2 - 8 |
| GIF Frame Delay | In 1/100 s | Value 50 = 500 ms |