cat
Change-Id: I4dbdf52d31d81edaa999725b23461e37a3e44f65
This commit is contained in:
parent
d5cdbda0f9
commit
4cc12d5e17
24
cat.txt
Normal file
24
cat.txt
Normal file
@ -0,0 +1,24 @@
|
||||
import Image
|
||||
|
||||
grey2char = ['@', '#', '$', '%', '&', '?', '*', 'o', '/', '{', '[', '(', '|', '!', '^', '~', '-', '_', ':', ';', ',',
|
||||
'.', '`', ' ']
|
||||
count = len(grey2char)
|
||||
|
||||
|
||||
def toText(image_file):
|
||||
image_file = image_file.convert('L') # 转灰度
|
||||
result = '' # 储存字符串
|
||||
for h in range(0, image_file.size[1]): # height
|
||||
for w in range(0, image_file.size[0]): # width
|
||||
gray = image_file.getpixel((w, h))
|
||||
result += grey2char[int(gray / (255 / (count - 1)))]
|
||||
result += '\r\n'
|
||||
return result
|
||||
|
||||
|
||||
image_file = Image.open("nyanko.jpg") # 打开图片
|
||||
image_file = image_file.resize((int(image_file.size[0]*0.2), int(image_file.size[1] * 0.1))) # 调整图片大小
|
||||
|
||||
output = open('outputcat.txt', 'w')
|
||||
output.write(toText(image_file))
|
||||
output.close()
|
Loading…
x
Reference in New Issue
Block a user