Skip to content

image-to-ascii

A python program to convert an image into an ascii image

Introduction

This program allows you to convert images into ASCII art. It uses various parameters to control the conversion process, including image scaling, sharpness adjustment, brightness adjustment, character set, and more.

Installation

  1. Clone this repository to your local machine.
    git clone https://www.github.com/ajratnam/image-to-ascii.git
    
  2. Activate the poetry environment.
    poetry shell
    
  3. Install the dependencies.
    poetry install
    

Usage

The documentation for the program can be read here.

Examples

Here are some examples of how to use the program:

Convert an image to ASCII art.

from converter import image_to_ascii
print(image_to_ascii('images/angry_bird.jpg'))
This converts the image to ASCII art and prints it to the console. ascii_angry_bird

Save the ASCII art to an image.

from converter import image_to_ascii, ascii_to_image
ascii_art = image_to_ascii('images/angry_bird.jpg')
ascii_art_image = ascii_to_image(ascii_art)
ascii_art_image.save('images/angry_bird_ascii.jpg')
This saves the ASCII art to an image file on your computer.

Change the size of the ascii art by absolute pixels.

from converter import image_to_ascii
print(image_to_ascii("images/angry_bird.jpg", size=(30, 30)))
This resizes the ASCII art to look like 30x30 characters(but it is actually 60x30 pixels). ascii_angry_bird_resized

Change the size of the ascii art by absolute pixels but do not try to maintain visual aspect ratio.

from converter import image_to_ascii
print(image_to_ascii("images/angry_bird.jpg", size=(30, 30), fix_scaling=False))
This resizes the ASCII art to 30x30 characters.

ascii_angry_bird_resized

Change the size of the ascii art by relative scaling.

from converter import image_to_ascii
print(image_to_ascii("images/angry_bird.jpg", scale=0.5))
This resizes the ASCII art to 50% of the original size. ascii_angry_bird_resized

Brighten the ascii art.

from converter import image_to_ascii
print(image_to_ascii("images/angry_bird.jpg", brightness=3))
This increases the brightness of the ASCII art to 3 times the original. ascii_angry_bird_resized

Darken the ascii art.

from converter import image_to_ascii
print(image_to_ascii("images/angry_bird.jpg", brightness=0.2))
This decreases the brightness of the ASCII art to 20% of the original. ascii_angry_bird_resized

Sharpen the ascii art.

from converter import image_to_ascii
print(image_to_ascii("images/angry_bird.jpg", sharpness=3))
This increases the sharpness of the ASCII art to 3 times the original. ascii_angry_bird_resized

Blur the ascii art.

from converter import image_to_ascii
print(image_to_ascii("images/angry_bird.jpg", sharpness=0.2))
This decreases the sharpness of the ASCII art to 20% of the original. ascii_angry_bird_resized

Change the character set used to generate the ascii art.

from converter import image_to_ascii
print(image_to_ascii("images/angry_bird.jpg", charset=' ░▒▓█'))
Changes the characters used to generate the ASCII art. ascii_angry_bird_resized

from converter import image_to_ascii
print(image_to_ascii("images/angry_bird.jpg", colorful=True))
Prints the ASCII art colorfully to the console. ascii_angry_bird_resized

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! If you have any suggestions or improvements, feel free to create an issue or a pull request. Install the additional development dependencies with poetry install --dev. Run coverage test with python -m pytest --cov