Skip to content

luan-arita/ASCII_art

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ASCII-Art

A program that turns images into ASCII Art.

It is created by extracting RGB tuples from all of the image's pixels (with the help of Pillow), converting those into single-value brightness numbers and, finally, associating those brightness numbers into its respective ASCII character (which are ordered from thinnest to boldest).

It also features colored images. The RGB values are converted into binary numbers through bitwise operators, which allows us to identify which colors between the three (R, G, B) are most predominant in the pixel and, consequently, 8 possible colors to view.

Other features that could be implemented are GIF support, another method for a broader color identification and a possible GUI.

WindowsTerminal_MvnmkYNLTf

Usage

  1. Download main.py
  2. Add your image in the same folder as main.py.
  3. Execute:
python -u main.py imageFilename [-i] [-c] [-m {1, 2, 3}] [-hs HEIGHT]

positional arguments:

filename Name of the image file

optional arguments:

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

-i, --invert: Inverts all the brightness.

-c, --color: Adds colours to the image.

-m {1,2,3}, --map {1,2,3}: Choose brightness mappings. 1 for Average, 2 for Lightness and 3 for Luminosity.

-hs HEIGHT, --height HEIGHT: Choose image size by adjusting its height.

Features

  • Three different ways of mapping RGB values into brightness:
    • Average: (R + G + B) / 3
    • Lightness: (max(R, G, B) + min(R, G, B)) / 2
    • Luminosity: 0.21 R + 0.72 G + 0.07 B

  • Invert image brightness

sai2_3s7Xr3GIjt

  • Change image resolution

WindowsTerminal_nVsjMgO2EO

  • 8 different colors

WindowsTerminal_AeUBm8FAJE

Known Issues

  • Depending on the program you're using to view the ASCII Art the image's aspect ratio may look wrong. That's because of the height of the characters, whereas in Windows Command Prompt, for example, has characters roughly three times tall as they are wide. To fix this, we have to print each character in each row two to three times to stretch the image back out. This can be easily changed in the function get_ASCII_matrix. I personally used Window's Terminal, but using Notepad or any other program may end up looking different.

Contact

Luan Arita - [email protected]

Acknowledgements

License

This project is licensed under the MIT License - see the LICENSE file for details

About

Image to ASCII converter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages