Skip to content

Generate ANSI-/Ascii-art version images/Gifs in your terminal.

License

Notifications You must be signed in to change notification settings

EtoDemerzel0427/ANSI-art

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Generate ANSI-/Ascii-art version images/Gifs in your terminal.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages