Turn a picture into a string via Python
Funny, funny, see a friend of that page's picture, I think about it, or get a skin kachulu
The picture is as follows:
The picture name is ccc.jpg code inside can change
The code is as follows:
#--coding:utf-8-- fromPIL Import Imageimport argparsewidth= -HEIGHT= $Ascii_char= List ("@#&$*ox!i;.") def Get_char (R, G, B, alpha= the): ifAlpha = =0: return ' 'length=Len (Ascii_char) Gray=int(0.299* R +0.578* g +0.114*b) Unit= (256.0+1) /lengthreturnascii_char[int(Gray/unit)]if__name__ = ='__main__': Im= Image.open ('ccc.jpg') Scale= Max (im.size[0]/WIDTH, im.size[1] /HEIGHT) WIDTH= im.size[0]/scale *2HEIGHT= im.size[1] /Scale im=im.resize ((WIDTH, HEIGHT), image.nearest) txt="" forIinchRange (HEIGHT): forJinchRange (WIDTH): txt+ = Get_char (*Im.getpixel ((J, I)) # reads (j,i) The R,g,b,alpha value of the pixel points is used to calculate the grayscale txt+='\ n'# After printing a line, wrap # Characters draw output to file with open ("output.txt",'W') asf:f.write (TXT)
Results
Turn a picture into a string via Python