2019独角兽企业重金招聘Python工程师标准>>>
新成果!
渣实现……
import Image
#import sys#filename = sys.argv[1]filename = 'a.jpg'def i2a(filename):"""turn an image into ascii"""im = Image.open(filename)im = im.convert('L')im.thumbnail((80, 80))string = ''for y in range(im.size[1]):for x in range(im.size[0]):p = im.getpixel((x, y))s = '.'if p > 200:s = '--'elif p > 150:s = '11'elif p > 100:s = '88'elif p > 50:s = 'MM'if x % im.size[0] == 0 and y > 0:s = s + '\n'string = string + sreturn stringascii = i2a(filename)
with open('a.txt', 'wb') as f:f.write(ascii)