Skip to main content

No project description provided

Project description

Convert image/gif/video to ascii art. If you inputs have plenty of frames, you can specify --fast to use torch accelerating the peocess.

Screen Shot

example example1

Experimental feature

Now you can add --alpha to generate neovim highlight definitions, for example:

img2art xxx.png --scale 0.1 --threshold 120 --save-raw ./xxx.lua --alpha

It will generate code definitions in target file which consists of two parts:

  1. Code of setting neovim highlight like vim.api.nvim_set_hl(0, "I2A0", { fg="#2f3651" }), which will be plenty of lines.
  2. The difinition of alpha header, which consists of the mapping between every pixels and highlights and the ascii art warppered by [[ ]] every single line.

Require the generated lua file and set properly in your config of alpha-nvim (assign header to dashboard.section.header), it will be:

example2

If img2art generate too much lines, you can specify --quant n to reduce the color level of input image. n is a positive integer which should be smaller than 256.

img2art xxx.png --scale 0.1 --threshold 120 --save-raw ./xxx.lua --alpha --quant 16

Installation

requirements: typer[all], opencv-python, numpy

pip install img2art

Usage

img2art --help

result:

 Usage: img2art [OPTIONS] SOURCE

╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────────────╮
│ *    source      TEXT  Path to image [default: None] [required]                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --with-color    --no-with-color                                  Whether use color. If you specify       │
│                                                                  alpha, with-color will be forcely set   │
│                                                                  to True.                                │
│                                                                  [default: no-with-color]                │
│ --scale                            FLOAT                         Scale applied to image [default: 1.0]   │
│ --threshold                        INTEGER                       Threshold applied to image, default to  │
│                                                                  OSTU                                    │
│                                                                  [default: -1]                           │
│ --save-raw                         TEXT                          Whether to save the raw data            │
│                                                                  [default: None]                         │
│ --bg-color                         <INTEGER INTEGER INTEGER>...  Backgound color, (-1, -1, -1) for none  │
│                                                                  [default: -1, -1, -1]                   │
│ --fast          --no-fast                                        Whether use torch to accelerate when    │
│                                                                  you inputs have plenty of frames.       │
│                                                                  [default: no-fast]                      │
│ --chunk-size                       INTEGER                       Chunk size of Videos or Gifs when using │
│                                                                  torch.                                  │
│                                                                  [default: 1024]                         │
│ --alpha         --no-alpha                                       Whether generating lua code for         │
│                                                                  alpha-nvim.                             │
│                                                                  [default: no-alpha]                     │
│ --quant                            INTEGER                       Apply color quantization. [default: -1] │
│ --mapping                          TEXT                          User-define ascii characters, need to   │
│                                                                  be from light to dark. The quant will   │
│                                                                  be forcely set to length of mapping.    │
│ --loop          --no-loop                                        Loop the output when input is GIF or    │
│                                                                  Video, use Ctrl-C to end this.          │
│                                                                  [default: no-loop]                      │
│ --interval                         FLOAT                         Interval when playing GIF or Video      │
│                                                                  output.                                 │
│                                                                  [default: 0.05]                         │
│ --help                                                           Show this message and exit.             │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
img2art path/to/image --scale 0.5 --with-color --threshold 127 --bg-color 255, 255, 255 --save-raw path/to/save.txt --alpha --quant 16

Use your own characters mappings:

img2art path/to/image --scale 0.1 --with-color --threshold 127 --bg-color 255, 255, 255 --save-raw path/to/save.txt --alpha --mapping " ^*!#@%"

For output of gif or video, you can write a shell script to play it or use some tools like rustyAscii.

Reference

bobibo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

img2art-0.4.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

img2art-0.4.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file img2art-0.4.2.tar.gz.

File metadata

  • Download URL: img2art-0.4.2.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.8.0

File hashes

Hashes for img2art-0.4.2.tar.gz
Algorithm Hash digest
SHA256 02ad25098dca93d3a5dc9b3bd2e53e50b5d2639287df4fd73f1b3ff15a12fc8a
MD5 8c4963d95ec5df2735c7782477be235e
BLAKE2b-256 d10ce9bae6e1a8357c1e9b73bdd0460d6640cae9e55c60052a1a8666928673fc

See more details on using hashes here.

File details

Details for the file img2art-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: img2art-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.8.0

File hashes

Hashes for img2art-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b9304f89966074a3a1abfeb2fdf94a95e80bb2d801498ee416d4e2d439018210
MD5 bc5b1f5b8523dd74ad70d074b04e7d11
BLAKE2b-256 fb7fd7f7e3215f6687dccd90379f829a3ead5841a6104e5735bd9305645d034e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page