asciitopgm
Convert ASCII art to PGM image
TLDR
Read ASCII data as input and produce a PGM image with pixel values that are an approximation of the "brightness" of the ASCII characters
Display version
SYNOPSIS
asciitopgm [width] [height] [<inputfile>]
PARAMETERS
width
Output image width in pixels. Optional integer; defaults to 128.
height
Output image height in pixels. Optional integer; defaults to 128.
inputfile
ASCII input file. Optional; uses stdin if omitted or set to -.
DESCRIPTION
Asciitopgm is a command-line tool from the Netpbm graphics toolkit that converts plain ASCII text or artwork into a PGM (Portable Graymap) image, a simple grayscale bitmap format.
It reads a stream of ASCII characters from standard input or a file, arranging them into a grid of specified dimensions. Each unique character is mapped to one of 70 discrete gray levels, from white (' ') to black ('@'), based on a fixed ordered sequence. Lighter characters like . and ' produce brighter pixels, while denser ones like * and # yield darker shades. The mapping scales linearly from 0 (lightest) to 255 (darkest).
The output image fills row-by-row: if input provides fewer characters than needed, spaces pad the remainder; excess input is truncated. This makes it ideal for vectorizing retro ASCII art, BBS graphics, or textual data visualizations into editable images.
Common workflow: pipe ASCII text to asciitopgm 256 64 | pnmtopng > art.png for PNG export. It's lightweight, lossless for the input charset, and integrates seamlessly with other Netpbm converters for further processing like colorization or scaling.
CAVEATS
Limited to 70 mappable ASCII characters; unmapped chars treated as black. Low resolution due to text grid; pads/truncates input without warning. No color support or font options.
GRAY LEVEL MAPPING
Fixed sequence (lightest to darkest, scaled 0-255):
' ' . \' \` , : ; \" ! i < > * ~ = + - a b c d | / \\ u v w x y z { } [ ] ( ) 1 2 3 ... @ % & * #
70 chars total; others map to max darkness.
HISTORY
Part of Netpbm suite, originated in late 1980s by Jef Poskanzer for Unix graphics processing. Evolved through community contributions; stable in modern Linux distros via netpbm package.
SEE ALSO
pbmtoascii(1), pgm(5), netpbm(1), pnmtopng(1)


