Making An ASCII-ART GENERATOR!? [PYTHON BEGINNER PROJECT TUTORIAL]

Поделиться
HTML-код
  • Опубликовано: 25 июл 2024
  • ASCII-ART is sick. Today we'll try to make a generator to make it for us, using PYTHON.
    Check out the source code on this page: raphsonite.github.io/
    Thoughts? Comment down below! Thank you for watching and see you in the next one!




    Check my socials:
    Instagram: @raphson_
    Soundcloud: @Raphson_
    RUclips: @Raphson
    #programming #python #ascii-art
  • ХоббиХобби

Комментарии • 93

  • @Akascape
    @Akascape 2 года назад +8

    Hello, I have figured out the solution for the issue of converting some png images. It used to fail the process with only 32 bit png files because it cannot process the alpha channel of 32 bit depth. So just a simple solution is to change the line no.21 "im = Image.open('file.png')" with "im = Image.open('file.png').convert('RGB')" which will simply remove any alpha channel from the image.

    • @Raphson
      @Raphson  2 года назад

      Well found, sir!

  • @abhradeepdey9054
    @abhradeepdey9054 3 года назад +1

    Tyvm, i actually learnt some concepts of image processing

  • @jacksonbernardo670
    @jacksonbernardo670 3 года назад +2

    Dude this is awesome! I cannoy believe that this program was made in Python :0

  • @notyrants507
    @notyrants507 3 месяца назад

    Thank you so much! I did this just for fun but it was super good to do it to learn new packages and some new loops! Thanks!

    • @Raphson
      @Raphson  3 месяца назад

      Happy to help!

  • @csbluechip
    @csbluechip 3 года назад +7

    Awesome ... It's like listening to the inside of my head while I'm coding LOL

  • @PaulJoshi
    @PaulJoshi 4 года назад +1

    Dude this is Gold!!❤❤

  • @GeneralBlorp
    @GeneralBlorp 3 года назад +2

    Great job!

  • @richardfeynman3856
    @richardfeynman3856 4 года назад +3

    Круто, мужик! Я очень впечатлён.
    Very cool man! I'm impressed.

  • @HeroGamer1
    @HeroGamer1 4 года назад +2

    New sub love your content!

  • @rubenrcs
    @rubenrcs 18 дней назад

    Thanks !

  • @hypercsgokl6220
    @hypercsgokl6220 2 года назад

    how do i add the image to the thing
    i've got a jpeg, but i have no clue on how to add the image onto the project

  • @youTubeViewer13
    @youTubeViewer13 3 года назад +2

    Awesome i love python very nice video. Very cool. i subscribe to your channel. excuse my english im French .

  • @barteksful
    @barteksful 3 года назад +1

    Is it possible to generate more pictures at the same time? For example, I have 100 images named 1.png, 2.png etc and would like to convert them to ascii faster than individually. What would I have to do in this case?

    • @Raphson
      @Raphson  3 года назад +1

      Hey man! Yeah that is definitely possible. What I would suggest is using a for-loop. A loop has an iterator, that cycles from 0 to 99. You can use that number to open the different files. Say you have those 100 images, you can open 0.png by creating a string from that iterator. Something like: str(iterator)+".png", or similar. You can save the files also from that loop, using the same strategy to name the files. Don't hesitate to ask more if you do get stuck. Cheers.

  • @fahadkhan-qz7nz
    @fahadkhan-qz7nz 3 года назад +3

    Bro, i love the way u code

  • @mageshkumar3318
    @mageshkumar3318 2 года назад

    i am running this in visual studio code idk where my out put is

  • @pranavsridhar1902
    @pranavsridhar1902 3 года назад

    Hai,how to copy the path of the font?

  • @kwkwbwjsj
    @kwkwbwjsj 4 года назад +1

    Nice video! but I have some problem following your intructions. I typed the exact thing like you and my txt file looks like its extended in up and down side.
    what would be wrong with my file...? Also it seems side part of the characters are torn away

    • @Raphson
      @Raphson  4 года назад

      Hey man, thanx! I think maybe you got line wrapping enabled in your notepad? Also, for that extending part, check 10:53. There I have the same problem. I will post the source code today (check description), so that you can check if that works for you.

    • @igotsomespace
      @igotsomespace 4 года назад +1

      @@Raphson Hi just checking to see if the source code was posted, I checked the description and the links do not lead to it. I really...really enjoyed this video, I hope you will have interest and time to make more videos like it. You are very skilled with Python programming : )

    • @Raphson
      @Raphson  4 года назад

      @@igotsomespace Hey! Thank you for your kind words! I did indeed forget to upload the code, thank you for reminding me! I will do it tonight! Promised! I will definitely make more videos like this as well! Cheers!

  • @roisanggung951
    @roisanggung951 2 года назад

    can i make it using google collabs?

  • @pablomora7880
    @pablomora7880 3 года назад +2

    Impressive! Man did u do it by your now? i mean did you check stackoverflow? im new to coding and these blows my mind! very abstract!

    • @Raphson
      @Raphson  3 года назад +4

      Hey man! I did use a bit of stack overflow to figure stuff out. Stack overflow is liturally the source of coding projects.

    • @pablomora7880
      @pablomora7880 3 года назад +1

      @@Raphson ANy tips for improving coding skills?

    • @Raphson
      @Raphson  3 года назад +3

      I think the best way to learn is to just do loads of random stuff! And always dare to ask everyone around you or on the internet if you get stuck!

  • @blockchaindomain
    @blockchaindomain 2 года назад +3

    I keep getting this error on alot of my photos.. any tips?
    Traceback (most recent call last):
    File "D:\ASCII\Asciigen.py", line 35, in
    r, g, b = pix[j, i]
    TypeError: cannot unpack non-iterable int object
    [Finished in 0.208s]

    • @Raphson
      @Raphson  2 года назад +2

      Yeh its a bit older and some png's are different than others. Ive recently tried the code again and indeed there are some weird issues, probably header format of the png. Sorry that I cannot give you an exact solution.

    • @blockchaindomain
      @blockchaindomain 2 года назад +1

      That's okay I learned a lot from your video and I appreciate you making this easy to understand

  • @aswinjose9475
    @aswinjose9475 3 года назад +1

    Hey just couldn't understand why do we use load? Is it similar to image.getdata

    • @Raphson
      @Raphson  3 года назад

      You are right, that is maybe a redundant thing to do.

    • @aswinjose9475
      @aswinjose9475 3 года назад

      @@Raphson No, I'm just starting to code, couldn't really understand the difference, 😅.
      Thanks ☺.

  • @S_--
    @S_-- 2 года назад

    I installed Pillow but its telling me that there isnt a module named "PIL"?

    • @Raphson
      @Raphson  2 года назад

      Try finding an updated turorial just on how pillow needs to be adressed. It might be initialised differently, as this video is 3 years old now! The rest of the code will be the same methods though!

  • @vanmanhtran4813
    @vanmanhtran4813 3 года назад +1

    Thank you, guy! But I have one problem: how to print output on terminal instead of render png file? Thank again.

    • @Raphson
      @Raphson  3 года назад

      Simply use pythons print command!

    • @vanmanhtran4813
      @vanmanhtran4813 3 года назад

      @@Raphson I have no idea in order to print with file png :(( pls assist me

  • @TSPTHUNDER
    @TSPTHUNDER 3 года назад +1

    till 5:21 .....i write and when i run the black and white image is not generated ...i use pycharm....plz help

    • @TSPTHUNDER
      @TSPTHUNDER 3 года назад

      and it says 'method' object is not subscriptable
      at r, g, b = pix[j, i] line

    • @Raphson
      @Raphson  3 года назад +1

      Could you first try to use a different image? Some PNG's apparently have a different structure or so, that might cause this.

    • @TSPTHUNDER
      @TSPTHUNDER 3 года назад

      I am trying... For two days....i also mail u plz check the mail...and help me....
      Its saying error in ImageFont.py line 836 833 193.....that means the package.... How is it possible... I'm frustrated man...plz help...

    • @Raphson
      @Raphson  3 года назад +2

      Haha okay man I have time tonight to check it, okay? I'll be back.

  • @user-zp9gb7tk7d
    @user-zp9gb7tk7d 4 года назад +1

    Hey, man. Could you tell me how to pass your code so that the resulting image is black and white, not color?

    • @user-zp9gb7tk7d
      @user-zp9gb7tk7d 4 года назад +1

      I really liked your video, very informative, but I'm new to programming and it was interesting. I tried to change it myself, but it didn't work :(

    • @Raphson
      @Raphson  4 года назад

      Alright I checked the code real quick because it is a while ago that I made that code, but I think you should change line 39, where it says "fill = (r, g, b)" to "fill = (h, h, h)". You can download my code from the description!
      Good luck, let me know if it doesn't work like you wanted!

  • @electrifywiz8491
    @electrifywiz8491 3 года назад

    im using pycharm to run this code..
    but im not getting any output..

    • @Raphson
      @Raphson  3 года назад

      It should create files in the directory where your script runs.

  • @usertechgamer2310
    @usertechgamer2310 4 года назад +1

    how to fix
    too many values to unpack?

    • @Raphson
      @Raphson  4 года назад

      Try a different image. Apparently there are different formats within png.

    • @usertechgamer2310
      @usertechgamer2310 4 года назад

      @@Raphson it works, can I use your code to make a tkinter version of this?

    • @Raphson
      @Raphson  4 года назад

      @@usertechgamer2310 Definately dude! If you feel like it let me know how it turned out, always cool to see!

  • @mofogamingttv9835
    @mofogamingttv9835 2 года назад

    I'm stuck on how Python is able to get the amount of pixels/dimensions

    • @Raphson
      @Raphson  2 года назад

      Send me a dm on insta, lets see if i can help!

  • @joedew4183
    @joedew4183 3 года назад

    **FIXED**
    the part "d.text((j*oneCharWidth, i*oneCharHeight), getChar(h), font = fnt, fill = (r, g, b))" does not work for me.
    Heres the error code
    Traceback (most recent call last):
    File "C:\Users\joeve\Desktop\Python\ASCII convertor\main.py", line 38, in
    d.text((j*oneCharWidth, i*oneCharHeight), getChar(h), font = fnt, fill = (r, g, b))
    NameError: name 'd' is not defined

  • @jiriheistein4372
    @jiriheistein4372 3 года назад

    no module PIL found ???

    • @Raphson
      @Raphson  3 года назад

      You will have to install that using PIP. Check this answer: stackoverflow.com/questions/20060096/installing-pil-with-pip

  • @gmodandhl2experiments849
    @gmodandhl2experiments849 2 года назад

    help, my ver wont run and it's throwing a error

  • @qlmob5547
    @qlmob5547 2 года назад

    What is your IDE?

  • @franklind.roosevel2863
    @franklind.roosevel2863 3 года назад +1

    i dont understand what [::-1] does
    you need to know i am very old

    • @Raphson
      @Raphson  3 года назад

      It stands for [start:stop:step], where start and stop are not filled in so the entire string is checked. Step is -1, so it steps backwards through the string! Hope this makes sense.

    • @franklind.roosevel2863
      @franklind.roosevel2863 3 года назад +1

      @@Raphson thanks

  • @g2renders781
    @g2renders781 4 года назад

    I received "ValueError: too many values to unpack (expected 3)" @ 5:32
    My Code:
    from PIL import Image, ImageDraw, ImageFont
    import math
    im = Image.open("C:/Users//Desktop/")
    width, height = im.size
    pix = im.load()
    print(width, height)
    for i in range(height):
    for j in range(width):
    r, g, b = pix[j, i]
    h = int(r/3 + g/3 + b/3)
    pix[j, i] = (h, h, h)
    im.save("output.png")

    • @Raphson
      @Raphson  4 года назад

      Okay so I ran your code and it worked perfectly fine man. I think it has to do with your input image, as I read in this thread: stackoverflow.com/questions/52666965/valueerror-too-many-values-to-unpack-expected-3-using-pil Try using another image man, maybe that helps. Let me know if you got it!

  • @lazizkhan1
    @lazizkhan1 3 года назад

    Who can write that all codes to here

    • @Raphson
      @Raphson  3 года назад

      Check raphsonite.github.io to download the code.

  • @ChrstphreCampbell
    @ChrstphreCampbell 3 года назад

    Like all of the ASCII generators that I’ve seen online, they invariably use a single character to represent a particular grayscale and I found that this creates a very blocky and rather ugly ASCII piece of art… Many years ago I wrote a program on my HP 48 that solves this by creating a string of characters starting with period And then comma and then ending with M & W, And then when I’m analyzing the source picture, I choose semi randomly from this list so that each character is within the range of the desired character density and the final artwork looks extremely smooth… ! If you’re interested in some examples look for “ASCII Art” on Flickr.… ! I have a version of this on _Scratch_ but unfortunately you need to download it to your own computer rather than use it on the Scratch platform because it’s just too complicated… ! scratch.mit.edu/projects/92282376
    Oops ! I thought this might be easy to find, but apparently it was not ( !!! ) there’s quite a bit of stuff here that’s related to mailart so you may have to scroll down a bit to find some representative images.… ! www.flickr.com/gp/chrstphre/ip05Bj

    • @Raphson
      @Raphson  3 года назад

      Do you have a link to an image that was created using your method?

    • @ChrstphreCampbell
      @ChrstphreCampbell 3 года назад

      @@Raphson I added a link to the original text. '

    • @Raphson
      @Raphson  3 года назад

      So if I understand correctly, you introduce random noise to cover up sharp transitions? Looks good!

    • @ChrstphreCampbell
      @ChrstphreCampbell 3 года назад +1

      @@Raphson no; I am choosing a character from a range that represents approximately that grayscale so that a letter like an R in an S would be approximately equal and you could use either an M or a W for the darkest things.… likewise a period Might be either a period or a comma or even a semicolon, I think that there’s usually about six choices that can be chosen from…

    • @Raphson
      @Raphson  3 года назад

      Exactly. Thats cool! Not too hard to implement in my code either. In the getChar method, simply add a random number to the index between for example -3 and 3, and cap them to prevent using invalid indexes.

  • @modaryaghi
    @modaryaghi 3 года назад +1

    Oh, your coding skell is bad, though I loved the output.

    • @Raphson
      @Raphson  3 года назад +2

      I guess... thanks!?

  • @anugupta6834
    @anugupta6834 2 года назад

    lol u aslo copy paste programmer

    • @Raphson
      @Raphson  2 года назад

      Isn't every programmer?

  • @Usertrappedindatabase
    @Usertrappedindatabase 3 года назад

    How could you directly call the image file instead of changing the link within the source each time?
    like:
    asciipy image1.jpg new_outputnamehere.txt/jpg/md/whatever. or just cat output to terminal??

    • @Raphson
      @Raphson  3 года назад

      Hey man! Yeah you are looking for using command line arguments! I don't know the syntax from the top of my head but I'm sure if you google python command line arguments it will pop up! Cheers!