Image sampling and brightness mapping
The source image is downsampled to a grid matching your chosen character width. Each cell's average brightness is computed and mapped onto an ordered ramp of characters, from sparse marks like a period or space for light areas to dense marks like @ or # for dark areas. Because monospace character cells are taller than they are wide, sampling the same number of rows as columns would stretch the image vertically when rendered as text, so the row count is reduced relative to the column count to compensate.