Generate ascii image of yours ?

Want to generate ASCII Image of you? or any image?

Here is the code few lines to make you happy

Allyou need to do is install PIL(Python Image library)

Run this code

Steps which i am following

1) Read Image  
2) Resize image
3) Convert it to grayscale
4) get RGB value.
5) map RGB values to ASCII chars

Lets convert this python image  














ASCII image looks like this



















Still you can achive high resolution ASCII image by selecting more specific charachters for different gray colors
Note: RGB values are tuple like (255,33,98)
For gray scale RGB value will be int starting from 255 to 0
255  is white
0 is black

code is here



 1 #!/usr/bin/python
  2 from PIL import Image
  3 from  PIL import ImageOps
  4 import xlwt,sys
  5
  6 x = 150
  7 y = 150
  8
  9 im = Image.open("/home/naren/naren/image.jpg")     # load image
 10 im.resize((x,y)).save('resize.jpg')
 11
 12 im = Image.open("/home/naren/naren/resize.jpg")    # saving image for ref
 13 output = ImageOps.grayscale(im)                    # convert to grayscale
 14 output.save('resize.jpg')
 15 im = Image.open("/home/naren/naren/resize.jpg")      
 16
 17 f = open("image.txt", "w")                         # open text file
 18
 19 for pixelx in range(0,x-1):
 20     f.write('\n')
 21     for pixely in range(0,y-1):
 22         color = im.getpixel((pixely,pixelx))
 23         if color <= 255 and color >= 253:ch = " "
 25         elif color <= 253 and color >= 250:ch = "."
 27         elif color <= 250 and color >= 230:ch = ","
 29         elif color <= 230 and color >= 210:ch = '"'
 31         elif color <= 210 and color >= 190:ch = '^'
 33         elif color <= 190 and color >= 170:ch = "%"
 35         elif color <= 170 and color >= 150:ch = "&"
 37         elif color <= 150 and color >= 130:ch = "a"
 39         elif color <= 130 and color >= 110:ch = "o"
 41         elif color <= 110 and color >= 90:ch = "0"
 43         elif color <= 90 and color >= 70:ch = 'L'
 45         elif color <= 70 and color >= 50:ch = 'y'
 47         elif color <= 50 and color >= 30:ch = "Y"
 49         elif color <= 30 and color >= 10:ch = "H"
 51         elif color < 10 and color >= 0:ch = "#"
 53         else:ch = " "
 56         f.write(ch)


Open with wordpad and ctrl+ mousewheel to change font size..   cheers :)