AsciiPhoto is a python script that takes in as input an image, and returns a text output that resembles the input image. In other words, it replicates an image with certain characters.
- For example, when the following image of Instagram logo -
is passed as a parameter into AsciiPhoto, the following output is observed -
,,,,,,,,?@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@?,,,,,,,,
,,,,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,,,,,
,,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,,,
,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,,
,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,
,:@@@@@@,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,@@@@@@,,
,@@@@@%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,S@@@@@,
,@@@@@,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:@@@@@@@*,@@@@@,
%@@@@,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,@@@@@@@@@,,@@@@?
@@@@@,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,@@@@@@@@@,,@@@@@
@@@@@,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,@@@@@@@@@,,@@@@@
@@@@@,,,,,,,,,,,,,,,,,,,,,,:*SS*:,,,,,,,,,,,@@@@@@@@@,,@@@@@
@@@@@,,,,,,,,,,,,,,,,,,,*@@@@@@@@@@*,,,,,,,,@@@@@@@@@,,@@@@@
@@@@@,,,,,,,,,,,,,,,,,@@@@@@@@@@@@@@@@,,,,,,@@@@@@@@@,,@@@@@
@@@@@,,,,,,,,,,,,,,,@@@@@@@@@@@@@@@@@@@@,,,,@@@@@@@@@,,@@@@@
@@@@@,,,,,,,,,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@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@?
,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,
,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,
,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,
,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,
,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,,
,,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,,,
,,,,,:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,,,,,
,,,,,,,,%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@?,,,,,,,,
AsciiPhoto works in a rather simple and intuitive way. Here's the algorithm -
- Resize the image to a standard dimension, while maintaining aspect ratio
- Convert to grayscale (the reason for doing so is because characters are replaced based on their intensity)
- Create list of special characters to replace pixels with
- Classify and divide pixels into buckets or groups, based on their intensity
- Replace all pixels in a bucket with the corresponding special character
- Print the text into terminal or write into a file
- Done
Clone the project
$ git clone https://github.com/c0d3x27/AsciiPhoto.git
Go to the project directory
$ cd AsciiPhoto
Install dependencies
$ pip install pillow
Run the python script, and pass the image path as the parameter
$ python AsciiPhoto.py `image_path`
The script will print the output in the terminal, and will also write into a file img.txt
in the same directory as the AsciiPhoto.py
Done!
- Alternatively support colored outputs by printing the text onto an image