-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpic2ch.py
More file actions
27 lines (24 loc) · 840 Bytes
/
pic2ch.py
File metadata and controls
27 lines (24 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#encoding:utf-8
from PIL import Image
import argparse
#-------------------------------------------------------
ascchar='''@#$%&?*aeoc=<{[(/l|!-_:;,."'^~` '''
count = len(ascchar)
def get_char(Imagefile):
Imagefile=Imagefile.convert("L")#转灰度
asd=''
for h in range(Imagefile.size[1]):
for w in range(Imagefile.size[0]):
grayImg=Imagefile.getpixel((w,h))
asd+=ascchar[int(grayImg/(256/(count)))]
asd+='\r\n'
return asd
if __name__== '__main__':
Imagefile = Image.open("dola.png")
Imagefile = Imagefile.resize((int(Imagefile.size[0]*0.8),int(Imagefile.size[1])))
print u'Info:',Imagefile.size[0],' ',Imagefile.size[1],' ',count
with open('tmp.txt','w') as f:
f.write(get_char(Imagefile))
# tmp=open('tmp1.txt','w')
# tmp.write(get_char(Imagefile))
# tmp.close()