HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

How to convert an Image into ASCII using Python

12,616 views January 12, 2020 6:13

Watch on YouTube
ChannelCodinity Groups

Description from the creator

**The image of the lady in this video is the prime minister of Finland**

We are performing below actions to generate the ascii art from image.

Get an image path as a command line argument.
Open the image from the provided path.
Calculate the aspect ratio.
Resize the image. Here we are taking new width as 120 pixels. Adjusting the new height as per aspect ratio.
Convert the image into greyscale format.
Get all the pixels of image. Replace pixles with intentsity in a defined range with a character from list.
Print image and save to text file.

If you are getting an elongated image in terminal, you can adjust the height accordingly. I am generating new_height using formula new_height = aspect_ratio * new_width * 0.55.

Statement list(img.getdata()) returns the list intensity of all pixels. Value of intensity will be between 0 to 255. Lower the value, darker the color. That is why we have characters in char list arranged from higher intensity to lower intensity.

Value of pixel//25, where 25 is the intensity range for one character, can be between 0 to 11 i.e why there are 11 characters in charslist. You may keep more characters in the list, let's say 16 characters and then keep the range size as 17.

Line new_pixels = [chars[pixel//25] for pixel in pixels] replaces the pixels with intensity from 0 to 25 with first character from chars list and 26 to 50 with seconds character from chars list and so on.

These are not my own codes.
Reference: dev.to/anuragrana/generating-ascii-art-from-col…

KeyWords:
python tutorial,
python snake,
python projects,
python programming,
python classes,
python terraria,
python live,
python automation,
python attack,
python ai,
python ark,
python api,
python algorithms,
python advanced,
python arrays,
python app,
python asyncio,
a python snake,
a python eating a deer,
a python eating,
a python versus anaconda,
a python versus a king cobra,
a python christmas,
a python versus alligator,
a python eating an elephant,
a python eating a crocodile,
a python got loose in our house,
python bangla tutorial,
python bite,
python beginner,
python bangla,
python beginner projects,
python bot,
python by healy,
python boots,
python blockchain,
cardi b python,
python programming b tech,
b tree python,
python b terraria,
b pattern in python,
b in regex python,
python a/b testing,
python b darija,
python crash course

About this tutorial

Codinity Groups published this 6:13 video tutorial on January 12, 2020. It has been watched 12,616 times on YouTube.

Category
Education
Duration
6:13
Published
January 12, 2020
Views
12,616
Likes
235

Tags

Share

This tutorial in other languages