A fast, simple, and reliable Command Line Interface (CLI) tool written in Rust that converts images into ASCII art text files.
- Automatic Resizing: Intelligently resizes the input image to fit standard terminal and text editor viewing while preserving the aspect ratio (taking into account character height/width ratios).
- Luminosity Mapping: Converts image pixels to grayscale using luminosity calculations and maps them to ASCII characters for accurate shading.
- Progress Feedback: Features a clean CLI spinner to show progress during generation and writing.
- Robust Parsing: Built with
clapto provide standard CLI flags, help menus, and error handling.
Ensure you have Rust and Cargo installed on your system.
Clone the repository and build the project:
git clone https://github.com/rb0rg/image-to-ascii-rs.git
cd image-to-ascii-rs
# Build the project in release mode for optimal performance
cargo build --releaseYou can also install the binary globally on your system:
cargo install --path .The CLI tool provides a generate subcommand to perform the image-to-ASCII conversion.
image-to-ascii generate [OPTIONS]| Argument | Short | Long | Required | Description |
|---|---|---|---|---|
| Input | -i |
--input |
Yes | The path to the source image file you want to convert (e.g., image.png, photo.jpg). The file must exist. |
| Output | -o |
--output |
Yes | The path to the folder where the resulting .txt file will be saved. The directory must already exist. |
Upon successful execution, the program will generate a plain text file (.txt) containing the ASCII representation of the image.
- The output file will inherit the file stem (the name without the extension) of the input image.
- For example, if your input is
inputs/profile_picture.pngand your output directory isoutputs/, the resulting file will be saved asoutputs/profile_picture.txt. - The tool will display a success message upon completion:
✔ Successfully generated ASCII version.
Basic Conversion:
image-to-ascii generate --input ./assets/logo.png --output ./documents/This command reads logo.png from the assets folder and writes the ASCII result to ./documents/logo.txt.
Using Short Flags:
image-to-ascii generate -i ./dog.jpeg -o ./This command reads dog.jpeg from the current directory and outputs dog.txt into the current directory.
Viewing Help:
image-to-ascii help
image-to-ascii generate --helpThe CLI safely handles common errors and will abort with descriptive messages if:
- The input image path does not exist.
- The output directory path does not exist.
- The input file is not a valid or supported image format.
This project is open-source. Feel free to modify, distribute, and contribute!