Contents that posted a long time ago may be obsolete and may not reflect my current opinion.
要走创意路线好吗!print 我爱你
之流怕不是在小学五年级奥塞的时候就玩腻的,真丢「理科生」的脸。
0x00 起因
本着善待接纳的态度,😂这人怕不是刚入计算机系的大一新(la)生(ji)吧。
当场分手 +1。
0x01 动手
代码优雅与否并不是重点=。=真正的秀,要让对面不懂代码的人能看得明白效果,并且觉得你写的有「卵」用。
不考虑什么「设计模式」、「依赖注入」、「最佳实践」之类的,劳资敲代码就是一把梭!
from PIL import Image
codeLib = '''@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,"^`'. ''' count = len(codeLib)
def transform(image_file): image_file = image_file.convert("L") codePic = '' for h in range(0, image_file.size[1]): for w in range(0, image_file.size[0]): gray = image_file.getpixel((w, h)) codePic = codePic + \ codeLib[int(((count-1)*gray)/256)] codePic = codePic + '\r\n' return codePic
fp = open(u'my-lover.jpg', 'rb') image_file = Image.open(fp) image_file = image_file.resize( (int(image_file.size[0]), int(image_file.size[1]*0.4))) print u'Info:', image_file.size[0], ' ', image_file.size[1]
result = open('result.txt', 'w') result.write(transform(image_file)) result.close()
|
以上代码修改自:https://blog.csdn.net/wait_nothing_alone/article/details/52901531
0x02 效果

0x03 秀