猫史档案馆


【Python作品分享】黑白字符画【作品秀】

用户:禁止挖坟后果自负禁止挖坟后果自负查看:0 回复:0 评论:0 创建时间:2020-11-08T19:25:18


【作品展示】

center_image

 

【作品介绍】

献给骂人的人

 

【作品源代码】

from PIL import Image,ImageDraw,ImageFont
import matplotlib.pyplot as plt
width, height = (60, 60)
i = Image.open("bcm.jpg").convert('L').resize((width, height))
plt.rcParams["image.cmap"] = "gray"
#plt.imshow(i)
#plt.show()
ASCII_HIGH='''$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. '''
t=''
for y in range(height):
    for x in range(width):
        p=(x,y)
        g=i.getpixel(p)
        index=int(g/256*70)
        t+=ASCII_HIGH[index]+' '
    t+='\n'
# print(t)
# with open('bcm.txt','w')as f:
#     f.write(t)
n=Image.new('RGB',(width*12,height*15),'white')
d=ImageDraw.Draw(n)
d.text((0,0),t,fill='black')
# plt.imshow(i)
# plt.show()
n.resize((width*12,width*12)).save('bcm_char.jpg')

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页