/AsciiPhoto

Convert any Photo into an ASCII image

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Built With Python GPL-3.0 License

Convert Photos into Ascii images using Python

Contents

What AsciiPhoto is?

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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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@?
,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,
,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,
,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,
,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,
,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,,
,,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,,,
,,,,,:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,,,,,,
,,,,,,,,%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@?,,,,,,,,

How AsciiPhoto works

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

How to use AsciiPhoto

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!


Future Plans

  • Alternatively support colored outputs by printing the text onto an image