elefcode
← All guides

Design · 3 min read

How Image to ASCII Art Conversion Works

ASCII art draws a picture with text characters. Converting a photo is a neat demonstration of how images are just grids of numbers.

Try it yourself with the related tool.

Convert an image to ASCII →

Advertisement

Brightness to characters

The image is shrunk to a grid — say 100 columns — and each cell's brightness is measured. A ramp of characters ordered from dense to sparse, such as @%#*+=-:. , assigns a dense character to dark cells and a space to bright ones. On a dark background, reverse the ramp.

Fix the aspect ratio

Characters are about twice as tall as they are wide, so a square grid of characters looks stretched. Sample half as many rows as columns to keep proportions right.

Getting a good result

High-contrast images with a clear subject work best; busy photos turn into noise. Boost contrast before converting, crop tightly, and view the result in a monospace font — in a proportional font, the columns will not line up.

Related guides