Coder Social home page Coder Social logo

image-to-ascii-art's Introduction

IMAGE TO ASCII ART

Convert any image into ASCII art.


Description

This program takes an image and produces a copy of it made entirely of ASCII printable characters; this copy can, therefore, be stored in a plain text file.

The idea is to take each pixel of the input image and, according to its brightness value, map it to a certain character.
Smaller characters like . or : are mapped to the brighter areas of the image, while bulkier ones like @ or # will be used to represent the shadows. (this behaviour can be changed)

The user can choose their own list of characters, I copied it from here.

NOTE: The text will only form a recognizable shape if displayed with a monospaced font.


Example Result

Below are shown a sample image and its text version side by side.
The ASCII text has been generated with a width of 350 and displayed with font size 10.

demo_image demo_ascii


Usage

Clone or download this project and cd into its root directory.

Launch the program with the following command:

python ascii.py path/to/image

If no path to an image file is specified via command line argument the program will try to open one of the sample images in the data/ directory.

Parameters

A few parameters have default values that can be changed inside the main file.

ASCII FILE PATH

Path to the text file in which to write the output.

OUTPUT WIDTH

Width for the ASCII text; intended as the maximum number of characters per line.
Based on this value, a corresponding height is calculated in order to preserve the aspect ratio of the input image.

Set this value to 0 to not alter the size.

Having a bigger "canvas" leads to a clearer image, with more details; the downside is that it would take a rather small font size to be able to display the picture in its entirety.

SEQUENCE

Array of characters to map to the image's pixels.
The characters must be sorted from lowest to highest "level of brightness".

PRODUCE NEGATIVE

This boolean value, when set to True, will produce a negative version of the image: mapping the "higher value" characters of SEQUENCE to the darker areas of the picture.

It should only be True when displaying black text on a light background.


Dependencies

  • python 3.6+

  • PIL module
    can be installed with the following command:

    pip install pillow

Author

Marco Plaitano


License

Distributed under the MIT license.

image-to-ascii-art's People

Contributors

marcoplaitano avatar

Watchers

 avatar

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.