Create Mesmerizing ASCII Art like Never Before with Aksharify
Tags: asciiart, python
Published: 2023-07-30 20:02:01

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](https://primepatel.github.io/), allowing you to explore the realm of creativity with Aksharify.


![Trinity Hall Prime](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/axuid8t5s4wuovosso74.png)

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.](https://primepatel.github.io/aksharify/getting-started/)

```python
!pip install aksharify
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/580en6w9iugvxanb8k7i.png)

```python
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)
```
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/632nv3b0ildut56m7r3i.png)

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.

```python
# Step 2: Customize Distribution
distribution = Linear("ABCDE", order=True)
distribution.show()
```
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qbb8zjvieb4cv7xo5awz.png)

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

```python
# Step 3: Generate ASCII Art
art = AksharArt(image, distribution)
art.aksharify(show=True)
```
![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3a80wxenv07o8q8vht8z.png)

```python
# 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)
```

![Final Ascii Art](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ch1a1vo2ge1ryjt27az4.png)


## Example 2


![Demon Slayer- Flame Hashira](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3vtuhp2ssfvbbdh8tmis.png)


```python
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
```

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tyfso6ojv4yce9h8d2p.png)

```python
# Step 2: Customize the distribution with chars="*"
distribution = Linear(chars="*")
```


```python
# Step 3: Create an EdgeArt object and generate ASCII art
art = EdgeArt(image, distribution)
art.aksharify(bg_char=" ", show=True)
```

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ardytieiywxgpr4fblv9.png)


```python
# 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)
```

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](https://primepatel.github.io/aksharify/) and create mesmerizing art from the realm of text characters!