Skip to content

WSE-research/image-to-ascii-art

Repository files navigation

Image To ASCII Converter

Do you want to create ASCII art from your images? Then this tool is for you. It is a web application that allows you to upload an image and convert it to ASCII art. Here, we did not implement yet another image-to-ASCII conversion algorithm. Instead, we use existing implementations and provide a web interface for them, s.t., the configuration, and conversion can be done in the web browser. The application is based on ascii-image-converter (available as a console application) and ASCII magic (Python library), so thanks for image generation go to the authors of these projects. However, our tool provides additional features like SVG, PNG, and ASCII export as well as a preview mode and many more. Here, we focus on providing an easy-to-use web interface that makes it easy to convert images to ASCII art and compare different results. This tool was implemented using the Streamlit library.




Screenshot of the Image-to-ASCII-Art UI (using a Pixabay image)

Features

  • Upload an image or directly use an image from the web (insert a URL)

  • Convert the image to ASCII art using 9 different algorithms/configurations (all of them are shown )

    • 3 with colorized characters (2 from ascii-image-converter, 1 from ASCII magic)

    • 3 with colorized character backgrounds (all from ascii-image-converter)

      • with a limited set of characters and a background color based on the average color of the pixels

      • with an extended set of characters and a background color based on the average color of the pixels

      • without characters and only background colors per position based on the average color of the pixels

    • 3 without using colors at all, i.e., only using characters (2 from ascii-image-converter, 1 from ASCII magic)

  • 24-bit colors are used to provide the best quality

  • Preview the different versions of the generated ASCII art

  • Define the preview background color (to simulate the background color of the target medium)

  • Download the generated ASCII art as a scalable image for lossless scaling (SVG), PNG, or plain ASCII text (e.g., to use it for a banner.txt of a Spring application)

    • note, even the text-based ASCII format will include the colors definitions using ANSI escape codes (supported by most shells)

  • Interactive configuration of the conversion process

Online Demo

The demo is available at https://demos.swe.htwk-leipzig.de/image-to-ascii-art/. Please note that the file upload limit is set here to 1 MB (definitely suitable for good quality).

Building and Running the Application

Running locally without Python

Install dependencies

Install Python dependencies
pip install -r requirements.txt
Install other dependencies

Note: just tested on Linux systems.

Run the Application

First, you need to define the location of the directory where the application should store the temporary files (e.g., the image files). Example:

export UPLOAD_DIRECTORY=/tmp/image-to-ascii-art

Thereafter, you can run the application using the following command:

streamlit run image-to-ascii-art-converter-web-ui.py --server.port=8501

or

python -m streamlit run image-to-ascii-art-converter-web-ui.py --server.port=8501

After that, you can access the application at http://localhost:8501.

Docker

The application is available at Dockerhub for free use in your environment.

Build Docker Image

docker build -t image-to-ascii-art:latest .

If you want to increase the upload larger, then change the server.maxUploadSize in the Dockerfile:

# set the limit to 5 MB
server.maxUploadSize=5

Run Docker Image

docker run --rm -p 8501:8501 --name image-to-ascii-art image-to-ascii-art:latest

Now, you can access the application at http://localhost:8501.

Contribute

We are happy to receive your contributions. Please create a pull request or an issue. As this tool is published under the MIT license, feel free to fork it and use it in your own projects.

Disclaimer

This tool just temporarily stores the image data. This tool is provided "as is" and without any warranty, express or implied.