Coder Social home page Coder Social logo

thefel0x / img2braille Goto Github PK

View Code? Open in Web Editor NEW
46.0 3.0 3.0 88 KB

Turns image into Unicode Braille art. (Now also with color!)

License: GNU General Public License v3.0

Python 100.00%
braille-characters braille-art ascii-art unicode-art unicode-characters unicode utf-16 image-processing art

img2braille's Introduction

CodeFactor

img2braille

Turns an Image into Braille Art with Pillow. (...or Unicode Art ...or "ASCII Art" (its not rly ascii))

Supports color now!

Installation

First make sure that you have Python 3 and pip installed. In the terminal:

git clone https://github.com/TheFel0x/img2braille
cd img2braille
python -m pip install -r requirements.txt

Then to run the script:

python script.py --help

Arguments

flag value description
input string (path) path to image file
-w --width integer output width (characters)
-i --noinvert - deactivates inverted dots. for light backgrounds with dark text
-d --dither - activates dithering
--calc RGBsum R G B BW determines the way in which is checked wether a dot is black or white
-n --noempty - don't use U+2800 "Braille pattern dots-0" (some applications remove these symbols because they treat them as spaces)
-c --color none ansi ansifg ansiall html htmlbg htmlall color support for either HTML style with font tags or ANSI escaped for cli use (html also puts br tags at the end of each line) htmlbg colors the background instead of the characters and all colors both
-a --autocontrast - enables autocontrast, to automatically adjust black and white values for calculations to the images max/min (recommended for black/white use)
-b --blank - all braille blocks are "full" blocks, in case you only care about the color output and not about the braille pattern

Examples

python script.py 'lain.png' --color ansi --dither --noempty image

python script.py 'lain.png' --dither dither-braille

python script.py 'lain.png' default-braille

python script.py 'lain.png' --noinvert noinvert-braille

How it works:

  • divide image into 2x4 pixel blocks
  • calculate the blocks value by adding the dot values to 0x2800
  • create braille character by outputting the final block value as a char (UTF-16 encoded)

Dot-values:

+1 +8
+2 +16
+4 +32
+64 +128

For calculating which braille symbol represents a 2x4 pixel block. The braille symbol works similar to an 8-bit binary number.

How do I save output?

Using the > operator, like this: python script.py 'lain.png' > output.txt

TODO:

  • support for different dithering algorithms
  • fix any bugs
  • support 3, 4 and 8 bit ANSI color mode
  • check if support for U+1FB00 to U+1FB3B (Block Sextant) might be possible
  • maybe edge detection filter?
  • maybe IRC color option?
  • color palette support? maybe using https://github.com/hbldh/hitherdither ?
  • adjust-aspect-ratio option (for non-monospace fonts that mess up the aspect ration of the output)

img2braille's People

Contributors

gideonbear avatar thefel0x 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

Watchers

 avatar  avatar  avatar

img2braille's Issues

Turn `img2braille` into a package

This will simplify the installation process to python3 -m pip install img2braille
The img2braille name is free on PyPI

Are you okay with me submitting some pull requests for this project? (e.g. making it a package, adding tests, enforcing PEP8, making a main function, using built-in argparse features instead of manual or statements, maybe more)

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.