- Saved searches
- Use saved searches to filter your results more quickly
- yattsu/image_to_ascii
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- License
- cleardusk/ImageToAscii
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Saved searches
- Use saved searches to filter your results more quickly
- License
- aypro-droid/image-to-ascii
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Turning your images to ASCII Art using Python
- Creating ASCII Art From An Image Using Python
- Loading an Image
- Resize The Image
- Convert Image to Grayscale
- Create an ASCII Character List
- Convert to ASCI Art
- The Complete Code
- Some Sample Outputs
- Conclusion
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A python script that converts images and gifs to ASCII
yattsu/image_to_ascii
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
This program converts images and gifs to ASCII
It can also display them in the terminal
Python==3.8.1
Pillow==7.0.0
Requests==2.22.0
It accepts images and gifs. You can specify the path or link (ending in .jpg/.png/.gif . )
Example: python ascii.py /path/to/file.png / python ascii.py https://site.domain/file.gif
You can specify the scale , reverse , chars , rotate , contrast and wide arguments
scale — scales the source file to the integer specified
Example: python ascii.py /path/to/file.gif scale 75
reverse — swaps black&white for the given file
Example: python ascii.py /path/to/file.gif reverse scale 10
chars — specifies the characters for conversion
Example: python ascii.py /path/to/file.jpg chars ‘ $@B%8&WM#’ (default is ‘ :co@’)
rotate — rotates the characters by either -90 or 90 degrees; the accepted values are ‘left’ and ‘right’
Example: python ascii.py /path/to/file.jpg rotate left
contrast — converts using these characters ‘ ░▒▓█’; this will override the chars arguments
Example: python ascii.py /path/to/file.jpg contrast
wide — specifies how wide each cell will be
Example: python ascii.py /path/to/file.jpg wide 3 (default is 2)
All arguments can be nested and combined
Displays the image/gif in the terminal. For gifs, it will infinitely loop through the frames
Example: python show.py
You can specify the s argument to specify the delay between frames
s — delay between frames, default is 0.07 seconds Example: python show.py s 0.3
About
A python script that converts images and gifs to ASCII
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Python tools for Image Ascii Art.
License
cleardusk/ImageToAscii
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
This is a simple, light and optimized image-to-ascii and ascii-to-image converter. It now supports image and video.
This conversion is implemented by mapping the intensity of pixel to characters with different shape.
-f | —file is input image path.
-s | —scale controls the output size.
-a | —aspect controls the aspect of height and width.
-w | —write-file is the output ascii txt path.
# lazy style: the default output is $.txt python img_to_ascii.py -f imgs/erke.jpg # adjust sampling step, the output is larger if it is samller python img_to_ascii.py -f imgs/erke.jpg -s 2 # complete style python img_to_ascii.py -f imgs/erke.jpg -s "auto" -w out.txt
You can adjust the font size of text editor for better view.
It calls the text drawing API of PIL to implement the rendering of ascii text to image.
python ascii_to_img.py -f imgs/kenan.txt -w imgs/kenan_ascii.jpg
python ascii_art.py -f videos/kenan.mp4 -s 1 -e 360 -w res/kenan.gif -p 10 --step=10 --scale=0.25 --sampling-step=6
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A simple python library to convert images to ASCII art
License
aypro-droid/image-to-ascii
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
image-to-ascii is a python module created for creating Ascii art from any given image
ASCII IMAGE
ORIGNAL IMAGE
ASCII IMAGE
ORIGINAL IMAGE \
pip install image_to_Ascii
If you want to install the newest version from git, you can install like this:
pip install git+https://github.com/aypro-droid/image-to-ascii.git
If you want to easily edit the source, it’s recommended to clone the git repo and install as develop like this. Make sure you have git installed. https://git-scm.com/
git clone https://github.com/aypro-droid/image-to-ascii.git python setup.py develop
How do I generate an Ascii art from image?
You can use any text editor you want, but personally I like to use VSC.
from image_to_ascii import ImageToAscii # imagePath is for path of the image you want to convert to Ascii # outputFile is for the file path of where the generated Ascii art should be stored keep None if you don't want to store it in a .txt file ImageToAscii(imagePath="path/to/file",outputFile="output.txt")
If you would like to contribute, go ahead! I appreciate it.
If you need any help you can ask me on discord Nai Aypro#1161
If you want to donate you can by going to https://paypal.me/waifly My bitcoin address: bc1qgvd5xsmc5vvmgr4t044f98wdcyxdk5gzwnac4l
All images are subject to copyright
About
A simple python library to convert images to ASCII art
Turning your images to ASCII Art using Python
In this tutorial, we will learn how to convert any image to ASCII art using the Python programming language. I’m sure you have heard of ASCII art which is a graphic design technique that uses printable ASCII characters to display images. Look at the image below for an example.
Now that we are clear with what we aim to do by the end of this tutorial. Let’s not waste any more time and begin the code implementation.
Creating ASCII Art From An Image Using Python
In this section, you will learn how to generate ASCII art from an image using Python.
Loading an Image
The first and foremost step is to load the image into our program using the PIL library. We will make use of the exception handling to make sure we handle errors beforehand. We will use a flag variable to know if the image is in the system or not.
Recommended Read: Python Exception Handling – Python try-except
import PIL.Image img_flag = True path = input("Enter the path to the image field : \n") try: img = PIL.Image.open(path) img_flag = True except: print(path, "Unable to find image ")
Resize The Image
We need to resize the image to a smaller width and height so that it doesn’t end up having too large text and create a mess.
width, height = img.size aspect_ratio = height/width new_width = 120 new_height = aspect_ratio * new_width * 0.55 img = img.resize((new_width, int(new_height)))
Convert Image to Grayscale
We can use the convert function and pass the option as L for GreyScale image output.
Create an ASCII Character List
Remember that the ASCII characters are arranged from darkest to lightest, which means for the list shown below the darkest pixel will be replaced with @ and lightest with . . You can change the list according to your preference.
Convert to ASCI Art
To convert the image to ASCII character, we get the pixel value for each pixel in the image and map the respective ASCII character together to form a new string. Now, we use to_greyscale function to convert our image to a GreyScale image and pixel_to_ascii function to convert our image to ASCII art! We will also save the resulting text into a file.
pixels = img.getdata() new_pixels = [chars[pixel//25] for pixel in pixels] new_pixels = ''.join(new_pixels) # split string of chars into multiple strings of length equal to new width and create a list new_pixels_count = len(new_pixels) ascii_image = [new_pixels[index:index + new_width] for index in range(0, new_pixels_count, new_width)] ascii_image = "\n".join(ascii_image) print(ascii_image) # write to a text file. with open("sample_ascii_image.txt", "w") as f: f.write(ascii_image)
The Complete Code
Let’s have a look at the complete code that we just coded in the previous section.
import PIL.Image img_flag = True path = input("Enter the path to the image field : \n") try: img = PIL.Image.open(path) img_flag = True except: print(path, "Unable to find image "); width, height = img.size aspect_ratio = height/width new_width = 120 new_height = aspect_ratio * new_width * 0.55 img = img.resize((new_width, int(new_height))) img = img.convert('L') chars = ["@", "J", "D", "%", "*", "P", "+", "Y", "$", ",", "."] pixels = img.getdata() new_pixels = [chars[pixel//25] for pixel in pixels] new_pixels = ''.join(new_pixels) new_pixels_count = len(new_pixels) ascii_image = [new_pixels[index:index + new_width] for index in range(0, new_pixels_count, new_width)] ascii_image = "\n".join(ascii_image) with open("ascii_image.txt", "w") as f: f.write(ascii_image)
Some Sample Outputs
Conclusion
Go ahead and try this exercise out with a lot of different characters and see the results for yourself. You might find some really interesting results too! Let us know in the comments below which one worked best for you.