ASCII Art: From Pixels to Characters — How Image-to-Text Conversion Actually Works
ASCII art converts images into text by mapping pixel brightness to characters of different visual density. Here's the algorithm behind it, the history that made it a computing tradition, and the surprising amount of perceptual science involved in choosing the right character ramp.
Before computers had graphical displays, they had printers. Before they had printers, they had teletypes. And on those teletypes — machines that could output nothing but rows of fixed-width characters — people made pictures. They typed or programmed sequences of characters that, when viewed at the right distance, formed recognizable images: portraits, landscapes, logos, and elaborate decorative patterns assembled entirely from the letters, numbers, and symbols of the ASCII character set.
This tradition — ASCII art — predates modern computing by decades. Typewriter art dates to the 1890s, teletype art flourished in the 1960s and 1970s, and ASCII art became a cultural phenomenon in the BBS and Usenet era of the 1980s and 1990s. Today it persists as a creative medium, a technical curiosity, and a practical format for contexts where only plain text is available: terminal output, code comments, email signatures, chat messages, and documentation.
The algorithmic side of ASCII art — automatically converting a photographic image into a grid of characters — is a fascinating exercise in perceptual mapping. It touches on grayscale conversion, spatial resampling, character density analysis, and the surprisingly complex question of how the human eye perceives brightness in a fixed-width font. This article explains the complete pipeline.
The History of Text-Based Images
The earliest known typewriter art dates to the 1890s, when people created pictures by typing characters at specific positions on a page. The medium was constrained — typewriters could not backspace precisely enough for fine work — but skilled typists produced portraits, landscapes, and geometric patterns that demonstrate remarkable artistry within severe constraints.
In the 1960s, mainframe computers with line printers opened new possibilities. The printers could output characters at precise, repeatable positions, and programs could generate the character sequences automatically. One of the earliest computer-generated artworks was created in 1963 by Kenneth Knowlton and Leon Harmon at Bell Labs — a large mural composed of electronic symbols that, viewed from a distance, resolved into a reclining nude figure. This work demonstrated the fundamental principle that all algorithmic ASCII art relies on: characters of different visual densities can approximate grayscale tones when viewed at a scale where individual characters blur into texture.
The BBS (Bulletin Board System) era of the 1980s and 1990s brought ASCII art to its cultural peak. BBSes transmitted data as plain text over dial-up modems, and their splash screens, file section headers, and message board decorations were rendered entirely in ASCII. Groups like ACiD Productions and iCE created elaborate artworks using the IBM PC's extended character set (Code Page 437), which included line-drawing characters, shading blocks, and other glyphs beyond the standard 95 printable ASCII characters. This era also produced ANSI art, which added color through ANSI escape codes — but the underlying technique of building images from characters remained the same.
Today, ASCII art has a nostalgic and retro appeal, but it also has practical uses. Terminal-based applications, README files, code comments, commit messages, and system monitoring dashboards all use ASCII art to add visual elements where graphical rendering is not available. And the algorithmic conversion of photographs to ASCII art remains a popular programming exercise and a useful creative tool.
The Conversion Algorithm
Converting a photographic image to ASCII art is a pipeline of four steps: grayscale conversion, spatial resampling, brightness measurement, and character mapping. Each step involves decisions that affect the quality of the final result.
Step 1: Grayscale conversion. Color information is not useful for standard ASCII art — the output is monochrome text. The image is converted to grayscale using luminance-weighted conversion, applying the BT.601 formula (0.299R + 0.587G + 0.114B) that we described in detail in our article on grayscale conversion. This produces a single brightness value for each pixel that accurately represents how bright the pixel appears to the human eye.
Step 2: Spatial resampling. A character in a monospaced font occupies a rectangular cell — typically about 8 pixels wide and 16 pixels tall (a 1:2 aspect ratio, though this varies by font). The image must be resampled to a grid where each cell corresponds to one output character. If the target output is 80 characters wide, and the source image is 1600 pixels wide, each character represents a 20-pixel-wide column. Because characters are taller than they are wide, the vertical sampling rate must be adjusted — each character represents approximately 40 pixels vertically (20 pixels times the aspect ratio of 2). The resampling computes the average brightness of all pixels within each cell, producing a brightness value for each character position.
This aspect ratio correction is critical. Without it, the ASCII art appears stretched vertically — a circle in the source image becomes a tall oval in the output. The exact correction factor depends on the font being used. For standard terminal fonts, a factor of roughly 0.5 (sample half as many rows as columns, relative to the pixel dimensions) produces correct proportions. Our image to ASCII art tool applies this correction automatically.
Step 3: Character density analysis. Each printable ASCII character has a visual density — the proportion of its bounding box that is filled with ink (or lit pixels on a screen). A space character has zero density. A period has very low density — a small dot in a mostly empty cell. An "at" sign (@) has high density — it fills most of its cell with strokes. A full block character (if using extended ASCII) has maximum density.
The density of a character depends on the specific font, size, and rendering. A period in one font might fill 3 percent of its cell; in another font, 5 percent. For algorithmic ASCII art, precise density values are less important than correct ordering — what matters is that the characters form a monotonic sequence from lightest to darkest.
Step 4: Character mapping. Each brightness value from the resampled grid is mapped to a character from the density ramp. The darkest pixels map to the densest characters; the lightest pixels map to the sparsest characters (or the reverse, depending on whether the output is displayed as dark text on a light background or light text on a dark background). The mapping is a simple linear interpolation: normalize the brightness to a 0-to-1 range, multiply by the number of characters in the ramp minus one, round to the nearest integer, and select the corresponding character.
The Character Ramp
The character ramp — the ordered sequence of characters from lightest to darkest — is the most important creative decision in ASCII art generation. Different ramps produce dramatically different results.
Paul Bourke's widely cited "standard" ramp uses 70 characters, from space (lightest) through increasingly dense punctuation, letters, and symbols to @ (darkest). A popular 10-level shorthand ramp is: space, period, colon, hyphen, equals, plus, asterisk, hash, percent, at-sign. This short ramp is less detailed but produces clean, readable results and works well for small output sizes.
The number of characters in the ramp determines the tonal resolution of the output. A 70-character ramp can represent 70 distinct brightness levels — enough for smooth gradations in large prints. A 10-character ramp represents only 10 levels — sufficient for recognizable images but with visible banding in gradients. For typical web output at 80 to 120 characters wide, a ramp of 10 to 20 characters provides a good balance between tonal range and visual clarity.
Longer ramps face a practical problem: human perception of character density is not linear, and the perceptual difference between adjacent characters in a long ramp may be imperceptible. Two characters with densities of 47 percent and 49 percent look identical at normal viewing distances. This means that extremely long ramps do not proportionally improve visual quality — beyond about 30 characters, you hit diminishing returns for most image sizes and viewing conditions.
Aspect Ratio: The Silent Quality Killer
The single most common flaw in ASCII art generators is incorrect aspect ratio handling. Monospaced font characters are not square — they are roughly twice as tall as they are wide. If the algorithm samples the image on a square grid (same number of pixels per character horizontally and vertically), the output will be stretched vertically by a factor of approximately two.
The fix is to account for the character cell aspect ratio during the resampling step. If each character cell is W pixels wide and H pixels tall, the image should be sampled in blocks of W by H pixels, not W by W pixels. For a typical terminal font where H is approximately 2W, this means each character represents twice as many vertical pixels as horizontal pixels.
Different fonts and rendering environments have different aspect ratios. A web page using Courier New at 14px might have a character cell of 8.4 by 17 pixels (ratio 2.02). A terminal using Monaco at 12px might have a cell of 7.2 by 14 pixels (ratio 1.94). A terminal using JetBrains Mono at 13px might have a cell of 7.8 by 18 pixels (ratio 2.31). For a browser-based tool that does not know the viewer's font, an aspect ratio of 2.0 is a safe default that produces good results in most monospaced font contexts.
Resolution and Detail
The number of characters in the output determines how much detail can be represented. An 80-character-wide output can represent roughly 80 distinct brightness samples across the image width — comparable to a thumbnail. A 200-character-wide output approaches the detail level of a small photograph and can represent recognizable faces, readable text, and fine structural detail.
However, wider output requires a wider viewing context. An 80-character-wide ASCII art piece fits in any standard terminal window or code editor. A 200-character-wide piece requires horizontal scrolling in most contexts, which disrupts the spatial relationships that make the image recognizable. The ideal width depends on the viewing context: 60 to 80 for terminal output, 80 to 120 for web display in a monospaced code block, and up to 200 for dedicated ASCII art viewing.
The source image resolution matters too. There is no benefit to converting a 100-pixel-wide source image to 200-character-wide ASCII art — each character would represent less than one source pixel, and the algorithm would be interpolating between pixels rather than averaging meaningful regions. The source image should have at least as many pixels (in the sampling dimension) as the target character count.
Our image to ASCII art tool lets you control the output width and automatically adjusts the vertical character count based on the aspect ratio correction. For best results, start with a source image that has been resized appropriately using our image resizer — a source resolution of 400 to 800 pixels wide produces good results for typical ASCII art widths.
Dark-on-Light vs. Light-on-Dark
The brightness-to-character mapping must be inverted depending on whether the output will be displayed as dark text on a light background or light text on a dark background.
For dark text on a white background (the default in most document contexts), a bright source pixel should map to a sparse character (like a space or period) because the white background shows through and the area appears bright. A dark source pixel should map to a dense character (like @ or #) because the dark ink fills the cell and the area appears dark. This is the "normal" polarity.
For light text on a dark background (typical of terminal emulators, code editors in dark mode, and many web code blocks), the mapping must be reversed. A bright source pixel should map to a dense character because the light-colored text fills the cell and appears bright against the dark background. A dark source pixel should map to a sparse character because the dark background shows through and the area appears dark.
Getting the polarity wrong produces a negative image — recognizable but with inverted tones that look eerie and wrong. Our image to ASCII art tool defaults to the polarity that matches most common viewing contexts and allows toggling if needed.
Beyond Brightness: Block-Based and Color ASCII Art
The brightness-mapping algorithm described above is the classic approach, but there are extensions that produce more detailed results.
Block-based matching goes beyond single-character density. Instead of mapping each cell to a character based on average brightness alone, it analyzes the spatial pattern within each cell — where the brightness is concentrated — and selects the character whose shape best matches that pattern. A cell with brightness concentrated in the upper-left might map to a backtick or apostrophe. A cell with brightness concentrated along the bottom might map to an underscore. This produces significantly more detailed results because it exploits character shape, not just character density, but it is computationally more expensive and requires pre-computing the spatial density maps of every candidate character.
Color ASCII art uses ANSI escape codes or HTML styling to assign colors to individual characters. Each character still represents brightness through its density, but its color is set to match the average color of the corresponding source region. The result combines the tonal detail of character density with the chromatic information of the original image. Color ASCII art can be strikingly detailed and is popular for terminal-based image viewers and README decorations. It is outside the scope of a standard text-output ASCII art tool but represents the state of the art for text-based image rendering.
Practical Applications
ASCII art conversion has several practical applications beyond creative expression.
Terminal-based image display is useful in SSH sessions, Docker container logs, CI/CD pipeline output, and any environment where only text output is available. Converting a chart, diagram, or status image to ASCII art allows visual information to be transmitted through text-only channels.
Documentation and README files use ASCII art for diagrams, architecture illustrations, and decorative elements. GitHub renders monospaced text in code blocks with consistent character spacing, making it a reliable environment for ASCII art display.
Accessibility is an unexpected application. For screen reader users, ASCII art is not directly accessible — a screen reader would read each character individually. But the conversion algorithm's brightness analysis can be repurposed: instead of mapping to characters, the brightness grid can be described in natural language ("a figure against a gradient background, bright on the left side, dark on the right"), providing a text description derived from the same perceptual analysis.
Data visualization in constrained environments — embedded systems with text-only displays, serial monitors, and telemetry systems — can use ASCII art rendering to display simple graphs, images, and status indicators where graphical output is not available.
The Bottom Line
ASCII art conversion is a luminance-mapping algorithm wrapped in decades of computing history and perceptual science. The pipeline is deceptively simple — convert to grayscale, resample to a character grid with aspect ratio correction, and map brightness to character density — but the quality of the output depends on getting every step right: proper luminance weighting (not a naive average), correct aspect ratio compensation for rectangular character cells, a well-ordered character ramp, and the right polarity for the viewing context. Our image to ASCII art tool handles all of these decisions automatically, producing clean ASCII art from any uploaded image directly in your browser.
References
Paul Bourke — Character Representation of Grey Scale Images — The foundational reference for ASCII art character ramps and brightness-to-character mapping, with the widely cited 70-character standard ramp.
Wikipedia — ASCII Art — Comprehensive history from typewriter art through BBS culture to modern applications, with examples and cultural context.
Bites of Code — Converting Images to ASCII Art (Part 1) — Step-by-step walkthrough of the conversion algorithm with code examples and visual comparisons of different ramp lengths.
Jonathan Petitcolas — Converting Image to ASCII Art — Detailed implementation guide covering Canvas pixel access, brightness calculation, and aspect ratio correction in JavaScript.
Asciiville — ASCII Art History — Timeline of text-based art from teletype to ANSI art, with historical context on BBS culture and the art groups that defined the medium.