DEV Community

Cover image for Create Mesmerizing ASCII Art like Never Before with Aksharify
Prime Patel
Prime Patel

Posted on

Create Mesmerizing ASCII Art like Never Before with Aksharify

In the world of digital expression, visuals often take center stage. But what if I told you that you can create stunning art using just text characters? Welcome to the realm of ASCII art, an ancient form of digital art!

In this article, we'll explore the world of ASCII art and delve into an exciting package called Aksharify. It is a powerful tool designed to simplify the creation of ASCII art, opening up a realm of creativity for enthusiasts and beginners alike.

Aksharify is an open-source python package hosted on GitHub, that simplifies the conversion of images into captivating ASCII art. It is currently maintained by me, allowing you to explore the realm of creativity with Aksharify.

Trinity Hall Prime

The journey of creativity often begins with a spark of inspiration. For me, it all started during my high school days when I encountered "The Trinity Hall Prime." This prime number, when arranged line by line, formed mesmerizing ASCII art. I was fascinated and curious about how such a large prime number could exist. This curiosity stayed with me throughout my graduation, where I was finally able to create ASCII art of Ramanujan using a single, massive prime number. I didn't know this curiosity would eventually lead to the creation of Aksharify. It took six months of dedicated efforts during my master's to develop this package.

Let's discover how this package can unlock the potential of text-based visual artistry.

Key Features of Aksharify

  • Diverse Distributions: Control character density and arrangement in your art with options like Linear, Exponential, and Normal distributions.
  • Customizable Character Sets: Unleash your creativity by customizing character sets for each distribution.
  • Versatility: Share and integrate art effortlessly with support for multiple output formats, including PDF, EPS, PNG, TXT, HTML, and SVG.
  • Ease of Use: Experience seamless image-to-ASCII conversion with Aksharify's simple API.

In the context of the Aksharify package, "distribution" refers to a method of assigning characters in the ASCII art representation based on their density or occurrence in the image. In simple words, the distribution determines how characters are mapped to different regions of the image according to the corresponding pixel values.

Excited to dive into the world of ASCII art? Let's Quickly Get Started with Aksharify on Google Colab! If you want to install locally, follow the instructions here.

!pip install aksharify
Enter fullscreen mode Exit fullscreen mode

We can create our ASCII art effortlessly with Aksharify's four-step process:

  1. Load Image: Use the Image class to load your image, either from a local file path or a URL.

  2. Customize Distribution: Select your preferred distribution (Linear, Exponential, or Normal) from the distributions module.

  3. Generate ASCII Art: Create an AksharArt object with your loaded image and chosen distribution. Create captivating ASCII art using the aksharify method.

  4. Output Art: Choose an output file format (e.g., PDF, PNG, SVG) by configuring the appropriate output class. Save your final ASCII art with the export method.

Let's start creating our first ASCII art using aksharify!

For a better and interactive experience, I highly recommend using Aksharify in the Notebook Environment! Notebook environment allows you to explore the full potential of the package and create mesmerizing ASCII art effortlessly.

Example 1

RRR- Ram Charan

from aksharify import AksharArt, hexify
from aksharify.image import Image
from aksharify.distributions import Linear
from aksharify.outputs import PNG

# Step 1: Load Image
image_url = "https://sm.mashable.com/mashable_in/seo/2/25689/25689_nevk.jpg"
image = Image(url=image_url)
image.resize(150)
image.normalize()
image.show(grayscale=True)
Enter fullscreen mode Exit fullscreen mode

The image may appear squeezed vertically, but this is intentional. It is because the height of ASCII characters is usually higher than their width, which helps maintain the correct aspect ratio of the resulting art.

# Step 2: Customize Distribution
distribution = Linear("ABCDE", order=True)
distribution.show()
Enter fullscreen mode Exit fullscreen mode

.show() method of distribution displays how ASCII characters are mapped to pixel value ranges in the image.

# Step 3: Generate ASCII Art
art = AksharArt(image, distribution)
art.aksharify(show=True)
Enter fullscreen mode Exit fullscreen mode


# Step 4: Output Art as PNG with black background
png_config = PNG()
png_config.file_name = "rrr"
png_config.bold = True
png_config.background_color = hexify("black")
png_config.height = 1080

# export Art as PNG
art.export(png_config)
Enter fullscreen mode Exit fullscreen mode

Final Ascii Art

Example 2

Demon Slayer- Flame Hashira

from aksharify import EdgeArt
from aksharify.image import Image
from aksharify.distributions import Exponential
from aksharify.outputs import PNG, TXT

# Step 1: Load the image from a file path
image = Image(path="FlameHashira.jpeg")
image.resize(200)
image.edgefy(show=True) # necessary for EdgeArt
Enter fullscreen mode Exit fullscreen mode


# Step 2: Customize the distribution with chars="*"
distribution = Linear(chars="*")
Enter fullscreen mode Exit fullscreen mode
# Step 3: Create an EdgeArt object and generate ASCII art
art = EdgeArt(image, distribution)
art.aksharify(bg_char=" ", show=True)
Enter fullscreen mode Exit fullscreen mode


# Step 4: Export the ASCII art to PNG with Black fill color
png_config = PNG()
png_config.file_name = "png_art"
png_config.fill_color = hexify("black")
# white color in hex format (can use hexify method instead)
png_config.background_color = "#ffffff"
png_config.width = 1080
txt_config = TXT()
txt_config.file_name = "txt_art"
art.export(png_config, txt_config)
Enter fullscreen mode Exit fullscreen mode

In just a few lines of code, you can witness the magic of Aksharify, where images come alive with the artistry of text characters.

Contribution

I welcome contributions from the community! Whether it's adding new features, fixing bugs, or improving the documentation, your contributions will help enhance Aksharify and make it even more powerful. Check out the GitHub repository and guidelines on how to contribute.

Bug Report

If you encounter any bugs or issues while using Aksharify, please feel free to submit a bug report on GitHub. Your feedback is invaluable in making Aksharify more robust and reliable.

Whether you're an art enthusiast or a curious beginner, Aksharify offers an enchanting journey into the world of ASCII artistry. See detailed docs and create mesmerizing art from the realm of text characters!

Top comments (0)