/artem

Convert images from multiple formats (jpg, png, webp, etc…) to ASCII art, written in Rust

Primary LanguageHTMLMozilla Public License 2.0MPL-2.0

artem crate Terminal Continuous Integration maintenance-status License: MPL 2.0

Artem

Artem is a small cli program, written in rust, to easily convert images to ascii art, named after the latin word for art. By default it tries to use truecolor, if the terminal does not support truecolor, it falls back to 16 Color ANSI. When the ascii image is written to a file, the image will not use colors. It supports .jpeg, .png, .gif, .webp and many more.

Examples

Input

_source: https://upload.wikimedia.org/wikipedia/commons/4/44/Abraham_Lincoln_head_on_shoulders_photo_portrait.jpg Abraham Lincoln

Output

Abraham Lincoln

Usage

For simply converting an image:

artem path

The input can either be one or multiple file paths or URLs.

NOTE: To use URLs, the web_image feature has to be enabled. It is enabled by default.

For more options use:

artem --help

To use custom ascii chars, use the --characters (or -c for short) argument.The characters should be ordered from darkest/densest to lightest. If the background should be invisible, add a space at the end. Alternatively this program has already 3 predefined character sets, accessibly by supplying the --characters argument to gether with the number (0, 1 or 2) of the preset that should be used. By default preset 1 is used.

artem PATH --characters "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789<>|,.-#+!$%&/()=?*'_:; "

To change the size at which the converted image is displayed, use:

#for auto sizing height
artem PATH --height
#for auto-sizing width
artem PATH --width
#for manual resizing use the --size flag
artem PATH --size 100

To save the the image to a file, use the --output flag.

artem PATH --output ascii.txt
#if the output file is an html file, the resulting ascii art will be saved as html ascii art
artem PATH --output ascii.html
# or alternatively, use an .asn file for colored ascii art
artem PATH --output ascii.ans

Using the --outline flag, the given input image will be filtered, to only contain an outline, which will then be converted. Please be aware, that this will take some additional time, as well as that it might not perfectly work on every image. For the best result, please use and image with a clear distinction between the background and the foreground.

artem PATH --outline

For an even better result, it might be worthwhile trying out the --hysteresis/--hys flag, potentially with characters better suited for outlines, for example.

artem PATH --outline --hysteresis --characters "|/\_.  "

Installation

All platforms (recommended)

The easiest way to install artem is using cargo with

cargo install artem

It will automatically add artem to your PATH variable, so it can used like shown in the usage section.

If cargo is not installed, visit the cargo book for installation instructions.

Linux

Debian-based Distributions (e.g. Ubuntu)

For Debian-based Distributions, like Ubuntu, download the .deb file from the release page and install it with:

sudo dpkg -i artem.deb

The .deb package also contains tab completions (for bash, zsh and fish) and a man page.

Archlinux-based Distributions

artem is available as an AUR package. You can install it with your favorite aur-helper, for example with yay:

yay -S artem

This will build it from source. Alternatively, it is also available as a precompiled binary (artem-bin):

yay -S artem-bin

Other Distributions

On other distributions use the binary file provided in the release tab.

Alternatively, if brew is installed, you can also use brew to install it. See the MacOS Homebrew section for more information.

MacOS

Using Homebrew

Warning: Currently the brew version is outdated and can be no longer recommend. This is due to brew providing only rust version 1.59.0. This project relies on features from 1.60.0. The progress can be tracked at the homebrew repo

The recommended way to install artem on MacOS is using a Homebrew tap:

brew install finefindus/tap/artem

The homebrew version has the added benefit of also installing the man page and tab completions for bash, zsh and fish.

Binary files

Alternatively binary files (for x86_64 and Arm) are provided in the release tab. This way of installing is NOT recommend over using brew or cargo.

Windows

To install the windows version, without using cargo, download either the gnu- or the mscv compiled .zip files from release tab and extract the .exe. It should be noted that you will have to add the .exe manually to the PATH variable.

Shell completions

artem has shell completions and a man page available. When using the homebrew version, the .deb package, or the aur versions, they are installed automatically, whilst for using the binary files with shell completions, the completion files, which be can be found in the compressed release file, have to be copied to the correct locations. Assuming the compressed file has been uncompressed, use following commands to copy the files to their correct location for unix-like systems:

Shell Completions and Man page

For bash:

#copy the bash completion file
sudo cp completions/artem.bash  /etc/bash_completion.d/

For zsh add the file to a $fpath directory:

#copy the zsh completion file
cp completions/_artem $fpath

For fish add the file to the fish completions directory:

#copy the fish completion file
cp completions/artem.fish $HOME/.config/fish/completions/

For Windows add . /path/to/_artem.ps1 (including the dot) to the PowerShell profile.

Man Page

artem also provides a man page for the binary releases contained in the doc directory. To view it using the -l flag for man to view a local file.

#view the local man page
man -l doc/artem.1

Building from source

Assuming you have rust/cargo installed, you can build the project with:

cargo build --release

The --release flag disables debugging options, increasing performance.

Visit the rust homepage for installation instructions if rust is not installed.

Features

This disables the default features, whilst enabling all other specified features:

cargo build --release --no-default-features --features FEATURES

For more information about the usage of features, please refer to the cargo book.

The following features are currently available:

  • web_image Accept Image URLs as input (enabled by default)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please be aware that it might take some time for someone to respond.

Credits/Inspiration

This projects was heavily inspired by jp2a as well as the coding train video on ascii art.

Also a big thanks to ripgrep for indirectly helping with inspiration for the build setup.

The following images are used for testing/examples:

Todo

  • Better average the RGB values of multiple pixel

  • Use the current terminal size to auto fit the image

  • Support ANSI terminal colors

  • Convert output to colored html

  • Use multithreading

  • Add tests

  • Add even more test

  • Convert multiple files at once

  • Automate copying of completion files from OUT_DIR to deployment/assets

  • Change name

  • Publish

Potential Ideas

  • Use edge detection and directional ascii

  • Implement better resizing

License

Mozilla Public License 2.0.