这是原图:
这是生成的字符画:
上代码:
import Image chars =" ...',;:clodxkLO0DGEKNWMM" fn=r'c:usersliabcdesktopjianbing.png' f1=lambda F:''.join([(k%100!=0) and m or m+' ' for k,m in enumerate(apply(lambda x:[chars[x[j,i]%len(chars)] for i in xrange(70) for j in xrange(100)],(Image.open(F).resize((100,70)).convert("L").load(),)),1)]) f=open(r"c:usersliabcdesktopaface.txt","w") f.write(f1(fn)) f.close()
其实仍然可以把所有代码继续压缩为1行的的..
就这样吧。