Expand description

This crate provides symbolize function that allows you to convert bitmap images into fine text art. It supports scaling the symbolized images as well as coloring them for terminals with RGB-support.

SymbolizeResult is a wrapper that allows you to easy convert a result to Vec<String>, Vec<u8> or String

The “original_image” parameter provides an original image as a DynamicImage

The “palette” parameter determines which characters will be used when converting the image. The symbols are arranged in descending order of the frequency of their appearance on the image.

The “scale” parameter determines the size of the output image relative to the size of the original.

The “filter_type” parameter defines what type of filtering will be used when scaling the image. For more info read FilterType docs.

The “colorize” parameter determines whether the output should be colorized for RGB-terminals or not.

Example usage:

use image::{imageops::FilterType, open};
use std::{process, error::Error};
use symbolize::symbolize;

fn main() -> Result<(), Box<dyn Error>> {
    let result = symbolize(
        open("./path/to/image.png")?
        &vec!['*', '#', '@', ' '],
        0.1,
        FilterType::Nearest,
        false,
    );

    match result {
        Err(e) => {
            eprintln!("{}", e);
            process::exit(1);
        }
        Ok(result) => {
            for line in Into::<Vec<String>>::into(result) {
                println!("{}", line)
            }
        }
    }

    Ok(())
}

Example output:

                              @@  @@@@  @@                              
                          @@  @@@@@@@@@@@@@@@@@@                        
                    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                    
                    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@            @@      
  @@  @@          @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@      @@@@      
  @@  @@@@        @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@      @@@@  @@@@
@@@@  @@@@    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@  
  @@@@@@@@    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@    @@@@@@@@  
    @@@@@@  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@    
      @@@@  @@@@@@@@@@@@@@@@@@&&    @@@@&&&&  @@@@@@@@@@@@@@  @@        
        @@@@@@@@@@@@@@@@@@@@@@&&    @@@@      @@@@@@@@@@@@@@@@@@        
          @@@@@@@@@@@@@@@@@@@@      @@@@      @@@@@@@@@@@@@@@@@@        
        @@@@@@##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@####@@@@@@      
          @@@@##  ####@@@@@@@@@@@@@@    @@@@@@@@@@####    ##@@@@        
            @@  ##        ######################        ##  @@          
              @@                                            @@          
                                                          @@

Structs

Helper wrapper struct that provides some Into implementations for easier convertation

Functions

Main function of this crate. Turns your bitmap image into text art.