Crate typographer

Crate typographer 

Source
Expand description

Advanced ASCII art generator. Key features:

  • Converts pixel luminance to ASCII characters.
  • Uses smart Canny edge-detection to improve feature readability.
  • Has customizable colour modes.
  • Compensates for the character aspect-ratio.
  • Highly configurable.

Also available as a CLI on GitHub.

§Basic Usage

The Typographer algorithm is composed of three sub-algorithms:

  • Fill: computes fill symbols from the gradient using pixel lumas.
  • Edges: computes symbols along the feature edges of the image.
  • Colours: computes symbol colours using one of several modes.

The algorithm is then ran with Typographer::render, which returns an AsciiImage represented as a 2D array of (possibly) styled symbols.

Run with default settings:

use typographer::{Typographer, Size, RgbImage};

let typographer = Typographer::new_coloured();
// let img: RgbImage
let ascii: AsciiImage = typographer.render(img, Size::Width(100));

for symbol in ascii.iter() {
    print!(symbol);
}

Run with custom settings:

use typographer::*;

let fill = Fill {
    gradient: "   .oO",
    ..Fill::default()
};
let edges = Edges {
    angles: ['|', '/', '-', '\\'], 
    sigma: 0.2,
    ..Edges::default()
};
let typographer = Typographer {
    luma_threshold: 0.4, 
    symbol_aspect_ratio: 2.2, 
    fill: Some(fill), 
    edges: Some(edges), 
    colours: None, // disable colours
    ..Typographer::default()
};
 
// let img: RgbImage
let ascii: AsciiImage = typographer.render(img, Size::Stretched(100, 200));

for symbol in ascii.iter() {
    print!(symbol);
}

Structs§

AsciiImage
Represents a rendered ASCII image.
Edges
Settings used when computing edge symbols using edge detection. The default settings work well enough in most cases, and are exposed for advanced usage only.
Fill
Settings used when computing fill symbols from lumas.
Typographer
Typographer entry-point.

Enums§

Colours
Settings used when computing symbol colours.
Size
Specifies the width/height of the output image, in symbols.

Type Aliases§

RgbImage
Input image with RGB pixels.
Sampler
Algorithm used to downsample images.
Styled
A “pixel” of the ASCII image. This has an aspect ratio defined by Typographer::symbol_aspect_ratio.