Skip to content
/ uniramp Public

🔣 A tool provides "unicode" character ramp information and image-to-text conversion

License

Notifications You must be signed in to change notification settings

Cycatz/uniramp

Repository files navigation

Uniramp

Introduction

  • Uniramp = Unicode + Ramp
    • Ramp: A char sequence for representing levels of gray values
    • “Standard” character ramp: $@B%8&WM*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,"^`'.
    • Support unicode character ramp information
  • Uniramp also provides the image-to-text script as a test ground
    • An ASCII “Unicode” art generator

Background

  • Most of image-to-text tools do not support custom charset
    • Either unicode characters, e.g., CJK characters
  • Also, the ramp lacks font information
    • A single character have different shapes over various fonts

Program Flow

flowchart.png

Installation

Install required packages:

Ubuntu 20.04:

apt install git \
            cmake \
            g++ \
            python3-dev \
            pybind11-dev \
            libfreetype-dev \
            python3-distutils \
            python3-pil

Clone the repo and build it:

git clone https://github.com/Cycatz-nycu/uniramp
cd uniramp
make

Run it with the example font:

python3 -m uniramp ramp -f tests/NotoSansCJK-Regular.ttc

Usage

Prefix arguments with python -m uniramp to use the program:

python -m uniramp -h 
usage: __main__.py [-h] {ramp,image} ...

positional arguments:
  {ramp,image}
    ramp        Print ramp infomation
    image       Convert an image to chars

options:
  -h, --help    show this help message and exit

Ramp

python -m uniramp ramp --help:

usage: __main__.py ramp [-h] -f FONT [-c CHARACTER_SET] [-g] [-w WIDTH]

options:
  -h, --help            show this help message and exit
  -f FONT, --font FONT  specify the font file
  -c CHARACTER_SET, --character-set CHARACTER_SET
                        specify the character set (default is [a-z][A-Z])
  -g, --graph           Print ramp graph
  -w WIDTH, --width WIDTH
                        specify the ramp bar width (default is 160 half-width characters)

Image

python -m uniramp image --help:

usage: __main__.py image [-h] -i IMAGE -f FONT [-c CHARACTER_SET] [-r] [-w WIDTH] [-o OUTFILE]

options:
  -h, --help            show this help message and exit
  -i IMAGE, --image IMAGE
                        specify the image
  -f FONT, --font FONT  specify the font file
  -c CHARACTER_SET, --character-set CHARACTER_SET
                        specify the character set (default is [a-z][A-Z])
  -r, --reverse         reverse the ramp order
  -w WIDTH, --width WIDTH
                        specify the generated image width (default is 80 characters)
  -o OUTFILE, --outfile OUTFILE
                        specify the output file (default the generated image will be printed to stdout)

Screenshot

Ramp

ASCII

  • Inconsolata Regular:

Inconsolata_ramp_black.png

  • Source Code Pro Regular:

source_code_pro_ramp_black.png

  • Fira Code Regular:

fira_code_ramp_black.png

CJK

  • Noto Serif CJK TC Regular (思源宋體)

noto_serif_cjk_tc_ramp_black.png

  • Noto Sans CJK TC Regular (思源黑體)

noto_sans_cjk_tc_ramp_black.png

Ramp Bar Graph

noto_sans_cjk_ramp_graph.png

Image to Text

Mona Lisa

monalisa_image_to_text_comparasion.png

Octocat

octocat_image_to_text_comparasion_4.png

Future Work

  • Maximum/Minimum coverage rate analysis
  • Half-width/full-width characters mixing
  • Color support (ANSI escape sequences!)
  • Conversion from generated text art back to an image

Reference

About

🔣 A tool provides "unicode" character ramp information and image-to-text conversion

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published