Coder Social home page Coder Social logo

orhnk / rascii Goto Github PK

View Code? Open in Web Editor NEW
170.0 3.0 3.0 163.02 MB

Advanced image to ASCII art tool & crate written in Rust ๐Ÿฆ€๐Ÿš€

License: MIT License

Rust 85.90% Shell 1.83% Nix 0.96% Python 11.32%
art ascii ascii-art command-line img img2ascii rust

rascii's Introduction

Crate Status Docs Status

RASCII Logo

Advanced ASCII Art Generator

Usage: rascii [OPTIONS] <FILENAME>

Arguments:
  <FILENAME>  Path to the image

Options:
  -w, --width <WIDTH>      Width of the output image. Defaults to 128 if width and height are not specified
  -H, --height <HEIGHT>    Height of the output image, if not specified, it will be calculated to keep the aspect ratio
  -c, --color              Whether to use colors in the output image
  -i, --invert             Inverts the weights of the characters. Useful for white backgrounds
  -C, --charset <CHARSET>  Characters used to render the image, from transparent to opaque. Built-in charsets: block, emoji, default, russian, slight [default: default]
  -h, --help               Print help
  -V, --version            Print version

Features

  • Available as a crate: RASCII has a very simple API allowing you to use RASCII from your programs without using the system shell.

  • Colored ASCII art generation: RASCII uses ANSI color codes to generate colored ASCII art.

    [!NOTE] Your terminal emulator has to support truecolor (don't worry, almost all modern terminal emulators do).

  • Super efficient colored output: RASCII never repeats the same ANSI color code if it is already active.

    This makes a huge difference in images with little alternating color, up to about 1800% reduction in output size. Woah!

  • Custom dimensions: RASCII allows you to give custom dimensions to the outputted ASCII art while keeping the aspect ratio (unless both dimensions are provided).

  • Custom charsets: RASCII allows you to use custom charsets to generate your ASCII art.

Note

The given charset must go from transparent to opaque.

  • Lots of pre-included charsets.

Installing The CLI

Via Cargo

Note

This is the recommended way of installing the RASCII CLI.

Warning

You must have ~/.cargo/bin/ in your PATH to run rascii directly.

cargo install rascii_art

Manually

Warning

this installation method is discouraged and only works for GNU/Linux or any other POSIX compatible systems!

git clone https://github.com/KoBruhh/RASCII && cd RASCII
chmod +x install.sh
./install.sh

Using The Crate

Instead of using the unreliable system shell to call RASCII, you can add the rascii_art crate to your project and use it in Rust!

To do so, run cargo add rascii_art to add RASCII to your Cargo project.

Here is a code example:

use rascii_art::{
    render_to,
    RenderOptions,
};
                                                            
fn main() {
    let mut buffer = String::new();
                                                            
    render_to(
        r"/path/to/image.png",
        &mut buffer,
        &RenderOptions::new()
            .width(100)
            .colored(true)
            .charset(&[".", ",", "-", "*", "ยฃ", "$", "#"]),
    )
    .unwrap();
}

Showcase

Japanese Charset

Emoji Charset

Note

The emoji charset does not guarantee your outputs color will match the color of your image, this is just a coincidence that happened with Ferris.

Chinese Charset

Block Charset

Custom ASCII Charset

You can use the --charset (or -C) CLI option to provide a custom charset to use when generating some ASCII art.

The value of this must option must go from transparent to opaque, like so:

rascii --charset " โ–‘โ–’โ–“โ–ˆ" --color ferris.png

Note that a charset similar to the above charset is available as a builtin named block.

Contributors

KoBruhh RGBCube felixonmars fnordpig


Note

There is a python script at repository root that can be used to generate the above contributor ASCII Art.

python contributors.py

rascii's People

Contributors

felixonmars avatar fnordpig avatar orhnk avatar rgbcube avatar szabgab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rascii's Issues

Unable to build on Windows 11?

Attempted to run with the recommended usage of cargo install rascii_art. However, code errors out at expanduser crate. Attached error message is included below:

   ...Other Packages/Crates
   Compiling serde v1.0.183                                                                                             
   Compiling parking_lot v0.12.1
   Compiling ahash v0.7.6
   Compiling time v0.1.45
   Compiling dirs v1.0.5                                                                                                
   Compiling pwd v1.4.0
   Compiling byteorder v1.4.3                                                                                           
   Compiling expanduser v1.2.2
   Compiling chrono v0.4.26
error[E0432]: unresolved import `pwd::Passwd`
  --> C:\Users\MyUser\.cargo\registry\src\index.crates.io-6f17d22bba15001f\expanduser-1.2.2\src\lib.rs:10:5
   |
10 | use pwd::Passwd;
   |     ^^^^^^^^^^^ no `Passwd` in the root

For more information about this error, try `rustc --explain E0432`.
error: could not compile `expanduser` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...

Is there a suggested fix for this? Thanks again!

Redundant method

rascii_art::render(_image) and rascii_art::render(_image)_to accomplish the same thing, and introduce confusing.

The code is also duplicated in the library making it longer to compile and not great in code quality.

Default character set contains characters that are length 2?

In the default character set:

pub const DEFAULT: &[&str] = &[
    " ", ".", "`", "^", "\"", "\\", ",", ":", ";", "I", "l", "!", "i", ">", "<", "~", "+", "_",
    "-", "?", "]", "[", "}", "{", "1", ")", "(", "|", "\\", "\\/", "/", "t", "f", "j", "r", "x",
    "n", "u", "v", "c", "z", "X", "Y", "U", "J", "C", "L", "Q", "0", "O", "Z", "m", "w", "q", "p",
    "d", "b", "k", "h", "a", "o", "*", "#", "M", "W", "&", "8", "%", "B", "$", "@",
];

Doesn't "\\/" result in two characters? When I send this sample image into it:
1uxv8fafhvm-luke-chesser

This causes the line to not be a uniform length:

-bash 2023-06-04 16-47-03

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.