convert images to ASCII characters!

hardik singh - May 15 '22 - - Dev Community

ever wanted to convert your image to Ascii characters? here is how you can achieve it!!

we will be converting this image of Mario, into ascii characters
Image description

step 1:- loading in the image and resizing

Image description
we resize the image since there are a LOT of pixels. so we resize it by 50%! this will make the final output smaller and we will not be compromising on the quality(since there are a lot of pixels to begin with!)

step 2:- converting the image to a pure black and white image

Image description
here we convert the image to a pure black and white image. we do this since text characters don't have color. now we can save this black and white data to a new image
Image description
here is what the image looks after the conversion!

step 3:- converting this black and white data to text characters

Image description
here we read in the data from the fresh black and white image which we saved in the last step. we also have a count variable which helps us to break the line for every time we finish a row section of the image
now we check the color of each of these pixels, if its black(0), we simply write in a "~". on the other hand if its white(255), we write in a "."
we now save this data into a text document!

here is how it looks like finally

Image description
I have resized my code editor so you all can see this masterpiece!

. . . . . . . . . . . .