您的位置:首页 > 其它

将图片输出成字符画

jerrism 2020-05-11 04:13 204 查看 https://blog.csdn.net/jerrism/

二值化后遍历像素即可。

from PIL import Image

SCALE = 0.05

def get_char(pixel, blank_char='⚪', fill_char='⚫'):
return blank_char if pixel == 0 else fill_char

if __name__ == '__main__':
im = Image.open(r"C:\Users\hmy\Downloads\timg.jpg")
size = im.size
width, height = int(size[0] * SCALE), int(size[1] * SCALE)
im = im.resize((width, height))
im = im.convert('1')

txt = ""
for i in range(height):
for j in range(width):
txt += get_char(im.getpixel((j, i)))
txt += '\n'
print(txt)

输入:
输出:

⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚫⚪⚫⚫⚫⚪⚪⚫⚪⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚫⚪⚪⚫⚪⚪⚫⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚪⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚫⚫⚫⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚫⚫⚪⚫⚪⚪⚫⚫⚪⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚫⚪⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚫⚪⚫⚫⚫⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚪⚫⚫⚫⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚫⚪⚫⚪⚫⚫⚪⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚫⚪⚪⚫⚪⚪⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚫⚪⚪⚫⚪⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚫⚪⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚫⚪⚪⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚪⚫⚪⚫⚪⚪⚫⚪⚪⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚫⚪⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚪⚪⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚫⚪⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚪⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚫⚪⚪⚪⚪⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚪⚫⚪⚫⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚫⚪⚪⚫⚪⚪⚪⚫⚪⚫⚪⚫⚫⚪⚫⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚪⚫⚪⚪⚫⚪⚪⚫⚪⚫⚪⚫⚫⚪⚫⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚫⚪⚪⚪⚪⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚪⚪⚫⚪⚪⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚪⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚫⚪⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚪⚫⚪⚫⚪⚪⚫⚪⚪⚫⚪⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚪⚪⚫⚪⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚪⚪⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚫⚪⚪⚪⚪⚫⚪⚫⚫⚪⚪⚫⚪⚫⚫⚪⚫⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚫⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫⚪⚫⚪⚫⚫⚪⚫⚪⚪⚫⚪⚫⚪⚪⚪⚪⚪⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚫⚪⚫⚪⚪⚫⚪⚫⚪⚫⚪⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚫⚪⚪⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚪⚫⚫⚪⚫⚪⚪⚫⚪⚪⚫⚪⚪⚪⚪⚫⚫⚫
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫

在点点圈圈中体现哲学之奥♂义

jerrism 原创文章 16获赞 1访问量 455 关注 私信
标签: