用户:
只因坤坤太美查看:0 回复:0 评论:0 创建时间:2022-07-24T19:25:24
【作品展示】

【作品介绍】
xxxxxxxx
【作品源代码】
from PIL import Image,ImageDraw
import matplotlib.pyplot as plt
width,height = (60,60)
img = Image.open("bcm.jpg").convert('L').resize((width, height))
plt.rcParams["image.cmap"]="gray"
# plt.imshow(img)
# plt.show()
ASCII_HIGH = '''$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. '''
txt = ''
for y in range(height):
for x in range(width):
pos = (x,y)
gray = img.getpixel(pos)
index = int(gray/256*70)
txt += ASCII_HIGH[index] + ' '
txt += '\n'
# print(txt)
# with open ('bcm.txt','w') as f:
# f.write(txt)
img_new = Image.new('RGB',(width*12,height*15),'white')
draw = ImageDraw.Draw(img_new)
draw.text((0,0),txt,fill='black')
# plt.imshow(img_new)
# plt.show()
img_new.resize((width*12,height*12)).save('bcm_char.jpg')
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn