Code Monkey home page Code Monkey logo

asciify's Introduction

Convert Images into ASCII Art with the power of Python

Contents

What ASCIIFY is

ASCIIFY 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 Octocat -

is passed as a parameter into ASCIIFY, the following output is observed -

....................................................................................................
....................................................................................................
.....................................####:...............####.......................................
.....................................#########################......................................
.....................................#########################......................................
.....................................########################.......................................
....................................###########################.....................................
...................................#############################....................................
...................................########?+?#######%++########....................................
...................................#####:::..::::::::::..::+####....................................
...................................####:::....::::::::.?..::####....................................
...................................####:::..?.::::::::?.?.::####....................................
...................................+###:::+??;::::::::???.::@###....................................
....................................###:::.??.::::::::.?..::###.....................................
.......................................###:::::::?::::::::###.......................................
........................................:####::::::::::@###.........................................
..................................###.......############............................................
..................................:,##.......@#######@..............................................
..................................:.##......###########.............................................
.....................................#:;....###########.............................................
......................................#@%#:S#####.#####@............................................
.......................................#######.##.######............................................
............................................##.##.######............................................
............................................##.##.######............................................
........................................::::##:##:######::::........................................
.....................................::::::###:##:###:###::::::.....................................
....................................,:::::::++##S::###++:::::::.....................................
.....................................:::::::++:++:++++++:::::::.....................................
.......................................:::::++:++:++++++:::::.......................................
..........................................::++:++:++++++::..........................................
..................................................,.................................................
....................................................................................................

How ASCIIFY works

ASCIIFY 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
  • Profit!

How to use ASCIIFY

  • Ensure you have the required dependency "PIL" for Python installed. (pip install pillow)
  • Clone the repo
  • Run the python script, and pass the image path as the parameter
  • The script will print the output in the terminal, and will also write into a file 'img.txt' in the same directory as the python script
  • Profit!

Future Plans

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

Support Me

If you liked this, leave a star! โญ

If you liked this and also liked my other work, be sure to follow me for more! ๐Ÿ™‚

asciify's People

Contributors

andrey-raspopov avatar rameshaditya avatar rattle99 avatar sichuan-pepper avatar wdhif 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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

asciify's Issues

Add support for videos

The idea is to allow users to stream videos in the terminal, by ascii-fying video frames as the video is playing.

Translate documentation into other languages

If you're fluent in languages other than English, feel free to submit a PR with the README file translated into your favorite language. ๐Ÿ™‚

Languages covered so far -

  • English
  • French
  • Greek

If you're familiar with another language, go right ahead and fork this repo and start contributing! :)

Add support to asciify URLs

Add support that lets users pass URLs of images as a command line argument and the script retrievers the image and asciifies it.

The inclusion of this could give rise to more use cases such as building streaming services that stream videos on the terminal, or viewing social media from the terminal.

ValueError: height and width must be > 0

Trying convert Image 7319167558_9ac77e8a54_b.jpg to ASCII get this error

$ python asciify.py 7319167558_9ac77e8a54_b.jpg
Traceback (most recent call last):
  File "asciify.py", line 86, in <module>
    runner(path)
  File "asciify.py", line 65, in runner
    image = do(image)
  File "asciify.py", line 40, in do
    image = resize(image)
  File "asciify.py", line 16, in resize
    new_image = image.resize(new_dim)
  File "/home/repodevs/.virtualenvs/asciify/local/lib/python2.7/site-packages/PIL/Image.py", line 1765, in resize
    return self._new(self.im.resize(size, resample, box))
ValueError: height and width must be > 0

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.