alex-转字符画


# 导图片入工具包
from PIL import Image

def getchar(gray):
    return '@'if gray > 128 else ' '


name = 'a.jpg'
width,height = 80,48
img = Image.open(name).resize((width,height)).convert('L')
# print(img)

text = ''
for y in range(height):
    for x in range(width):
        print(img.getpixel((x,y)))
        text += getchar(img.getpixel((x,y)))
    text = "\n"

print(text)

f = open("helokitty.txt", "w")
f.write(text)
f.close()
发布了552 篇原创文章 · 获赞 21 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/houlaos/article/details/105396692