How to convert an Image into ASCII using Python

preview_player
Показать описание
**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.

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.

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
Рекомендации по теме
Комментарии
Автор

Though I don't understand anything, it sounds awesome 🤣😂

surabhitalukdar
Автор

as you know me that i suck in coding.. but i really liked the background music you have used

sweatachakraborty
Автор

im homeless how to learn python can i get started searching books on a public place will help? i always want to learn some programming and python i like alot

gmerlin
Автор

Thank you so much bro. i wanted to ask why did you change sys.argv[1] to sys.argv[0] in to video

siddhanable
Автор

hi what does he he mean by this
Traceback (most recent call last):
File "app.py", line 4, in <module>
img = Image.open("profile")
File "C:\Users\zyad\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PIL\Image.py", line 2878, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'profile'

hibruh
Автор

I have this error how to do?
Traceback (most recent call last):
File "app.py", line 5, in <module>
image_path = sys.argv[1]
IndexError: list index out of range

JojoSociety
Автор

Can you explain what is
"from PIL"? i'm new on this

myonice.
Автор

i need to microsoft word??? can i use gmail one?

mikethegamedev
Автор

Is the layout of char important or can i fill in randome?

leweed
Автор

But it is not pixel precise converted pixel by pixel into the character set.

maxmuster
Автор

The background music is so distracting...yeah there are some people who liked that but I think they have listened to your background music instead of learning what you tried to teach in the video...

abdusamadabdusattorov