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.
- Download main.py
- Add your image in the same folder as
main.py
. - 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.
- 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
- Average:
- Invert image brightness
- Change image resolution
- 8 different colors
- 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.
Luan Arita - [email protected]
- Robert Heaton for guiding on how to make this project.
This project is licensed under the MIT License - see the LICENSE file for details