Git Product home page Git Product logo

ansi-art's Introduction

ANSI-Art

logo

NOTE: This toy project is not yet finished.

ANSI-version Logo

ansi-logo

Block ANSI-version Logo

block-ansi-logo

ASCII-version Logo

ascii-logo

Support Platform

You are kindly reminded to refer to this Github Gist to check whether your terminal meets the requirements to run ANSI-art. For the colored version, we rely on the "true color" of the terminal to preserve the initial RGB values. There are many terminal apps that supports true color, I recommend you to use iTerm2. However, it is sad to know that MacOS' terminal builtin (Terminal.app) does not support it. Don't run ANSI-art on it unless you are expecting a mess on your screen.

For the ASCII art version, this true color feature is not required.

Usage

To build the project and get the executable:

$ cd ANSI-art
$ go build -o ansi-art main.go

Then, with command ./ansi-art --help you will get the following help info:

ANSI-Art converts your image & Gif to ANSI characters (with color) that can show in the console.
Users can speicify the characters to use, size of the image, etc to get the best results. some sample commands are:

./ansi-art image pic/messi.png -W 150 -H 60 -a -C 40
./ansi-art gif pic/sharingan.gif -W 150 -H 60 -s SASUKE -d 300 -m bgm/uefa.mp3

Usage:
  ansi-art [command]

Available Commands:
  completion  generate the autocompletion script for the specified shell
  gif         Playing gif in your terminal.
  help        Help about any command
  image       Show your image in the terminal.

Flags:
  -h, --help   help for ansi-art

Now we look into subcommands.

Image

With Command ./ansi-art image --help, the following are displayed:

Show your image in the terminal.

Usage:
  ansi-art image [flags]

Flags:
  -a, --ascii             ansi or ascii art
  -b, --blockMode         character or block mode
  -C, --contrast float    increase/decrease the imgContrast (-100 ~ 100)
  -f, --filename string   the input gif file (default "demo.gif")
  -H, --height int        the resized height of the image (default 100)
  -h, --help              help for image
  -s, --seq string        the string of ANSI chars that build the image (default "01")
  -S, --sigma float       sharpening factor
  -W, --width int         the resized width of the image (default 100)

So a valid command can be:

./ansi-art image -f pic/messi.png -W 150 -H 60 -C 20 -S 10 -a

The output of this command is as follows: messi_output or

/ansi-art image -f pic/messi.png -W 150 -H 60 -C 20 -S 10 -s MESSI

This time the result is: messi_ansi Or you can add a -b command to the nearest above command to get the pixel version: messi_block NOTE that these are all displayed IN YOUR TERMINAL! (We will provide an export to image function later for sure though.) One last thing to remind is that --seq is only effective when no -a or -b is specified; when -a and -b show together, -a is of higher priority.

Gif

These are the output of command ./ansi-art gif --help:

Playing gif in your terminal.

Usage:
  ansi-art gif [flags]

Flags:
  -a, --ascii             ansi or ascii art
  -b, --blockMode         character or block mode
  -C, --contrast float    increase/decrease the imgContrast (-100 ~ 100)
  -d, --duration int      the duration(ms) of each frame, used to control speed (default 200)
  -f, --filename string   the input gif file (default "pic/demo.gif")
  -H, --height int        the resized height of the image (default 100)
  -h, --help              help for gif
  -L, --loop int          The loop number of the gif (default 1)
  -m, --music string      the background music file (default "bgm/smb.mp3")
  -s, --seq string        the string of ANSI chars that build the image (default "01")
  -S, --sigma float       sharpening factor
  -W, --width int         the resized width of the image (default 100)

Most flags are the same as in the image subcommand, with --duration, --loop, --duration, and --music as the new addons. The meaning of each flag is illustrated clearly above.

With command ./ansi-art gif -f pic/sharingan.gif -W 250 -H 60 -d 100 -a -m bgm/NadaNaruto.mp3 -C 30 -S 30 --loop 10, we can get:

sasuke.mp4

Likewise, command ./ansi-art gif -f pic/brother_fight.gif -W 150 -H 35 -d 200 -C 10 --seq BROTHER --loop 4 -m bgm/fight.mp3 can yield:

2021-07-28.10.04.56.mov

Codebase

  • art converts an image to ASCII-art or ANSI-art. For ANSI-art, there are text-based and block-based versions.
  • rank is used to rank the intensities of ascii symbols so that they can represent different grayscale values. Generally it is font-specific. My console uses monaco font, so I take it as an example. You are encouraged to try other fonts by downloading the ttf file to directory font, and change the line 56 to your font file. Currently it is hardcoded, but can be set as cli arguments. Forgive me for not doing so because of lazyness.
  • decode extracts frames from gif/videos. Currently only gif is supported.
  • cmd is used to set command arguments with the powerful package Cobra.
  • We also support background music playing with beep.

TODO

  1. Support mp4 decoding.
  2. Export the output to file: image/gif/mp4.
  3. Web version.

Reference

ansi-art's People

Contributors

etodemerzel0427 avatar

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.