haotianblog
Image to ANSI Art
Search
Ask the AI

Image to ANSI Art

Sample an image into 2×2 blocks and approximate each with a Unicode quadrant character plus 24-bit foreground/background colours. Each cell still has only two colours, not four independent colours or fourfold lossless resolution.

The converter does not upload images. Decoding, scaling and colour selection run in the browser; preview and download links belong to the current tab. The site may still load advertising, log visits or make other requests: browser-side conversion does not make the whole page offline.

Image to truecolor Unicode quadrant ANSI

Drop an image and the browser will resample it to a terminal grid, then encode each cell with Unicode quadrant blocks and 24-bit ANSI foreground/background colors.

Files are processed locally in this browser and are not uploaded; the generated download link and preview expire after 30 minutes.

Read the implementation notes
Download .ans
Waiting for an image

After downloading, run it in a truecolor-capable terminal: cat filename.ans


        

Why each cell gets only two colours

A terminal cell has one foreground and one background colour. Sixteen masks use space, U+2580/2584/2588/258C/2590 and U+2596–259F to choose which quadrants the foreground covers.

So the core of the conversion is not colour choice but picking, from those 16 masks, the one that minimises total error once the covered pixels take one colour and the rest take another. The tool tries all 16 masks on every 2×2 block, computes the optimal foreground and background for each, and keeps the lowest residual.

Three or more distinct input colours generally cannot be reconstructed with zero error using two colours, but mask selection can still reduce error. Sharp two-colour edges can be exact, while complex texture may not be. The linked four-pixel experiment provides checkable examples.

Using the output

The output is plain text carrying ANSI escape sequences. cat it to a terminal and it renders — given three preconditions:

  • Verify 24-bit support in the actual terminal. Unsupported sequences behave differently across configurations; this tool does not automatically generate a 256-colour file. Setting COLORTERM cannot add missing display capability.
  • The font must contain quadrant block glyphs. Missing glyphs render as boxes or blanks. Most monospaced programming fonts include them; some stripped-down fonts do not.
  • The line width must fit. Output width is fixed; a narrower terminal wraps every line and the whole image shears. Set the output width to the target terminal before converting.

Pasted somewhere that does not interpret escape sequences — most web text boxes, word processors — you will see runs of ESC[38;2;...m. That is not a generation fault; the receiver simply does not parse ANSI.

Parameters and verification boundaries

Columns control sampling, the cell height/width ratio controls shape, and background colour controls transparent-region compositing. Use the actual target terminal and font; a README or chat window that does not parse SGR will not display the text as an image. Output is capped at 260 rows and 62000 cells, which may reduce requested dimensions.

Colour sequences repeat only when the foreground/background pair changes, with additional line resets. Doubling width at fixed aspect approximately quadruples cells before the cap, not necessarily file bytes. Browser preview is not a substitute for checking the target terminal.

Related reading

Scroll down