Turn any image into ASCII art! (Easy Python PIL Tutorial)
ฝัง
- เผยแพร่เมื่อ 21 ก.ค. 2024
- This Python beginner tutorial shows you how to use the Python Image Library to build a short, interactive script to convert any image to ASCII art using the Python Image Library.
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. We made this TH-cam channel and Kite to help you be more productive: kite.com/download/?...
***************************************
JOIN our community of developers ► / 505658083720291
SUBSCRIBE for more Python tips, tutorials, and coding interview prep! ► th-cam.com/users/KiteHQ?sub_...
Follow us Twitter ► / kitehq
Github Repo ► github.com/kiteco/python-yout...
***************************************
ADDITIONAL BEGINNER RESOURCES:
6 Python Tips and Tricks YOU Should Know ►
• 6 Python Tips and Tric...
Push- Up Bot?! Make a Discord Bot in Python [step-by-step tutorial] ►
• Push- Up Bot?! Make a...
How to Build HANGMAN in 10 Minutes (Python tutorial) ►
• How to build HANGMAN w...
***************************************
Don’t forget to subscribe :)
th-cam.com/users/KiteHQ?sub_...
STAY TUNED:
Kite ► kite.com/
Twitter ► / kitehq
TH-cam ► / @kitehq - วิทยาศาสตร์และเทคโนโลยี
If you guys made it to the comments, let us know what images you turn (or want to turn) into a ASCII art!
it works so good!!
I don't know how to put images in comments using TH-cam, but it's so fine !! good job man!!
I got my script working after a long time.But it works really great.
:-)
I have a problem showing in sublime. It is showing :-
AttributeError: 'NoneType' object has no attribute 'convert'. I am using ubuntu
@@humptydumpty6323 can you please share your full trace back message?
This is video is great. I have been critiquing my coding in an attempt to improve, and my style is similar to yours and works very well for clean clear writing and editing but doesn't seem to be the norm. I think that people could learn a lot from you. Thank you.
Great tutorial! To maintain the image aspect ratio in ascii format i modified the ratio line of code:
ratio = height / width / 1.65
Thank You!
worked for me thanks! but what does 1.65 stand for
@@Canttakethatback Ascii characters hight and width are not equal. Hight is about 1.65 times bigger than width - depending on display. So to compensate that, i added / 1.65
With value 2 it's much better
@@Canttakethatback How do you actually do this? I tried to do a image of a celebrity to make my friend laugh. But when I copy n paste it doesnt work
That worked out perfectly for exactly what I needed. Big time thank you!
Hi Kite, I’m trying to use a livestream webcam, possibly around 1 sample per second, and covert the text in a defined region to ASCII to be stored in a csv. I’m very very new to python and so I’m wondering if you know how I might go about that
Such an underrated channel
You deserve better
interesting quick weekend project to tinker with. thank you!
how do I make the lines larger than 100 characters, I tried changing this line larger than 100 but that didn't make a difference.
resize_image(image, new_width=1680): any thoughts on how to make this bigger ?
Really cool video!
Would it be possible for you add a simple animation to visually explain what you are doing. Since i often find myself replaying parts of the video to get an idea what the code you wrote does.
Anyway, I recently found your channel, and i'm really enjoying your videos.
Hey could you help? I'm having trouble with the import PIL.Image. I've tried looking everywhere and see no info about how to get it to work
Ok, so I followed everything and I also had to install PILLOW module because PIL.Image is not an pre-installed package. And I also run the program and it runs smoothly but when showing the output it basically does nothing but show some dots, it looks nothing like the image I entered. I dont know why this is happening. Is it because I am using IDLE interpreter? If anyone knows why this is happening do let me know
Can you help me solve one error about : import "PIL.Image" could not be resolved from source Pylance(reportMissingModuleSource) [1,8]
Great tutorial. But you often just type and run over what you type quickly with absolutely no explanation as to what it is, so I'm left feeling like I just copied a code manually rather than learned something new.
can i initialize utf32 / unicode too . if it is what should write
How do u know that u need to do a floor division by 25?
does this work in IDLE python?
UnboundLocalError: local variable 'image' referenced before assignment
someone can help me??
im getting a few errors saying it has no attribute convert or getdata
actually i hav an issue
the resize function is not working quite right..my ascii is as tall as a giraf
I keep getting a ModuleNotFoundError for PIL. What shoudl I do?
is not a valid pathname to an image. (Solved)
In the first line change
import PIL
to
from PIL import Image
and in line 29 remove this
PIL.
Dude it still doesn’t work, I’m not sure what I’m doing wrong
@@niterider3622 the image and the code should be in same folder
@@DoubleFL3X there isn't a need tho lmao
winner here!!
Thanks
Thanks brother! this really helps me!
The main function is kinda sketchy.
Three level function argument passing doesn’t look that good. Anyone have that PEP reference for this?
Thaf list comprehension compromises readability.
Great tutorial! Thank you
Can we Try it Out in Android Devices in Pydroid3?
[Errno2] No such file or directory, it says when i command py script py
I can't find where my txt file is saved. Please help
Can anyone explain why do we devide pixels over 25?
Please tell me how can i get a pathname
def main(): not working. Just says its invalid syntax
it was great, super cool library. thxs
can you please upload it in github?
Thank you Kite!
how do i get PIL
more py tutorial, already subs
you went a little too fast but after making youtube play it at 0.75 speed this tutorial was amazing, thanks
definitely
Cool stuff!
PIL not working... Can anyone help?
by the time i wrote 'import PIL.Image', you already completed the try block! Please try to type a bit slower
For the aspect ratio to work you need to account for the character dimensions.
Was thinking about this few weeks ago wondering how it's been done
Likewise bro, but animated
When I try to copy n paste a image it doesnt work
good job!
Hey man, how would I do a python request for a url and pull an image of a chemical structure in the terminal? is it possible?
thanks
Idk if you're on linux, but I use wget and "url" in the terminal.
can someone give me the python file plz
I have an error that says "Unable to import 'PIL.Image' " and there was an unused variable 'image' what did I do wrong to correct it?
try running it using python3.9 or just install the module
What if, at the end, I want to export to Jpg or Jpeg instead of .txt? thanks !!
ascii is an format of characters that you type in, like these ones i am so there is no way u can do .jpg or .jpeg
Awesome!
Plz help me I have a error saying "local variable 'image' referenced before assignment
image is created in the try statement, check the output to see if the exception is printing
Hey my image paths dont seem to be working for some reason any fixes?
Replace with this line :
у меня что то не работает я не могу ему скормить картинку которую хочу преобразовать в ascii
Thank you
I managed to get work with image sets, as an animation of ASCII characters.
I added a few more input variables like number of images and image type, and added a frame delay so that it would print to the console with distinct frames instead of being to fast for the human eye.
The animation frames will just go on loop, because I though it would be underwhelming if it just showed the animation one time.
I wasn't able to install Kite. My CPU is not supported. Do I have any other option please?
have u found the solution?
it shows this ModuleNotFoundError: No module named PIL.image, though i have pillow installed in my system.
same problem did you find a fix?
Nice guide!
But what does 'pixel//25' stand for? When join method iterates through 'pixels' which type does 'pixel' get?
Thx a lot.
// is the operation for floor divison. This guarantees that we get an integer as the result. So "pixel//25" divides the intensity of the pixel by 25 and rounds it to the smaller integer. The important thing to notice is that he is using the result of "pixel//25" (e.g. let's say 3) to choose an element from the list of ASCII charachters he made earlier (so in our example, it would choose the 4th element, which is "%"). This is also why ASCII charachters were listed in descending intensity at the start.
@@gecicihesap901 Thanks for explaining when i changed ammount of ASCI chars i got error.
@@vojtechsokala3611 No problem, mate!
I would like to ask How can I add a comment that can be printed along with the image or after the image? Also, can I compile this Python code into a exe file?
I added the print() statement. Can this code be compiled with pyinstaller?
Hi, I keep on getting the error "not a valid pathname to an image"
as well as "UnboundLocalError: local variable 'image' referenced before assignment
Any help please?
insira a linha:
from the PIL import image
insert the line:
from the PIL import image
Replace with this line :
I have an error! it says ' ModuleNotFoundError: No module named ' PIL ' ' - if someone can help me, that would be great. thanks
sudo pip install Pillow
My program is not even opening.....why?
I get the following result:
"new_image_data = pixels_to_ascii(grayfy(resize_image(image)))
UnboundLocalError: local variable 'image' referenced before assignment"
I also
Can you tell me how to fix this
@@harmandeepsingh935 I'm affraid I can't. I'm sorry.
@@gabri3ltz its ok bro
make sure you return the image
Tysm :D
Very good!
it keeps saying invalid path for image even though the image is in same folder , I also give it full path.. help?
Same here - have you found a solution?
I save the project and images in a folder, but when I want to open the image there is a message ril.jpg is not a valid pathname to an image. can you help me?
Done.
how to fix this.?
I did cd desktop but it said that the system can’t find the given path
@That Coder ty
Hey sorry for the ignorance, but when i run the script it tells me no module named 'PIL'. This is my first time in Python so my bad haha.
same here. did not find a solution
How i made this into a .exe with a graphic interface? Anyone knows what i need to use to do? And i will ger with python language? - i tried to think in make a site and attempt to convert to exe but idk if work
use kivy for that
Use tkinter and pyinstaller
Pyinstaller need to be installed first.
After that convert the program using pyinstaller
im getting invalid path names, even though I copy the absolute pathname/ path from content root into the command prompt
same
what do you mean, how do i fix this
@@SalvettiRocco You need to write "from PIL import Image"
@@quahmingjun7246 You need to write "from PIL import Image"
@@gabrielesolms7048 You need to write "from PIL import Image"
when i try to run code it says ModuleNotFoundError: No module named 'PIL'
referring to the import PIL image how do i get this to work
In the command line write:
cd [here the path to the folder where your python file is]
And then:
pip install PIL
@@jonathanf680 where is the command line
@@xavierang3186 powershell or CMD
am i just slow or something i have him at 0.25 speed and i still cant follow hes so fast
Line 37??
All it does is that it keeps saying "'import' is not recognized as an internal or external command,
operable program or batch file."
I've followed everything else in the tutorial, but I'm really frustrated with the end result being nothing
In case you are still lost, you need to install a Python interpreter. There are many interpreters for Python, and I personally use the IDLE interpreter.
This sounds like you haven't properly set up python.
Ascii to image when?
3:14 can someone please explain the [ASCII_chars[pixel//25]] part please?
I am 5 months late, but here it is (copy of my previous comment):
// is the operation for floor divison. This guarantees that we get an integer as the result. So "pixel//25" divides the intensity of the pixel by 25 and rounds it to the smallest integer. The important thing to notice is that he is using the result of "pixel//25" (e.g. let's say 3) to choose an element from the list of ASCII charachters he made earlier (so in our example, it would choose the 4th element, which is "%"). This is also why ASCII charachters were listed in descending intensity at the start.
@@gecicihesap901 wow thanks so much. You helped me a lot
@@konstantineendeladze9029 No problem, mate! I am studying computer science, always a pleasure to help others who want to learn it.
bro can you please help me I am getting an issue:
"C:\Users\MY BOOK\Documents\thumb-1920-606500.jpg is not a valid pathname to an image."
bro I am stuck here please help me with a valuable info.
your projects are really cool I am liking it quite a lot.
In the first line change
import PIL
to
from PIL import Image
and in line 29 remove this
PIL.
@@DoubleFL3X Thaaaanks!!! This fixed the error
@@DoubleFL3X not fixing tho
I have a problem showing in sublime. It is showing :-
AttributeError: 'NoneType' object has no attribute 'convert'. I am using ubuntu
Can I just copy paste all this please? I'm not interested in coding and typing all this myself seems pointless
write from PIL import Image instead of import PIL
how to save as image instead txt ??
screenshot it
can anyone help me to solve "image pathname is invalid"
I get the same error! have you found any fixes? I'm on mac BTW
how to print it with color?
You can't
no module named PIL
youtube sent me notification today(5days later)😒😒 wtf TH-cam
does kite support Notepad++?
kite has been discontinued
is not a valid pathname to an image It says this
Nice tutorial. But i have a question, why does the ascii pixel is divided by 25?
Found answer?
Grayscale values are 0 - 255. You want to map that to 10 characters.
@@dancetothemusic99 isn't it 11 chars?
@@abhaynambiar271 Ah yes, 11 characters. Flat dividing any 0 to 255 by 10 will give you 11 results INCLUDING zero.
@@dancetothemusic99 ahhh that makes sense thanks
'function' object has no attribute 'convert' nooo
Is PIL.image inbuilt?
No
it just says that it's not a valid pathname to an image even though i use .jpg
Did you find a fix?
Try putting the image in the same folder as the code.
try from PIL import Image.
@@khwaishtongia1687 i tried every fix, but didn't worked!
same problem here
**sees doge on thumbnail**
me be like: I. MUST. CLICK. THE. MYTHICAL. DOGE
That was awesome ...👏👏👏👏
🙌 thank you!
Line 27: path = input("Enter a valid pathname to an image:
")
^
IndentationError: expected an indented block remove this 27?
indent it
What a great tutorial. Please share the Github link
Thanks for the reminder! We've added our repo link in the description. Here's the link for this project: github.com/kiteco/python-youtube-code/tree/master/ascii
Wait, i don't understand that //25
Dont work for me
I am using PyCharm and boy do I keep finding more errors
Hello bro, it says that "is not a valid pathname to an image." when I try to put. "picture.jpg" (this is the real name of picture)
@Chiba Liba I tried that but didn't worked!
same, i use ubuntu 20.04
In the first line change
import PIL
to
from PIL import Image
and in line 29 remove this
PIL.
@@DoubleFL3X thanks bro its working
@@DoubleFL3X Thanks man it worked!
I'd recommend to slow down the tutorial, because this guy is a speech machine
i agree... i'm a beginner, and... i am so lost, how do people talk so fast :(
Why I get this error?``` list index out of range```
Your ASCII character list doesn't have enough elements
OR
You forgot to do floor division
Thanks for replying but i figured out that my list had 1 element short 😅
i used the one on your git repo, gave it an image and it wont work
same :(
solved it write from PIL import Image instead of import PIL, then solve the warning that should appear
Nice
It says PIL.image module does not exist
you figure out how to install PIL?
@@cheems24 nope
my brain cells explode after watching this