用户:
AbnormalLOG查看:0 回复:3 评论:0 创建时间:2020-05-16T19:53:52
【作品展示】

【作品介绍】
生成彩色字符动画(萌新阶段🦊)
【作品源代码】
from PIL import Image,ImageDraw,ImageSequence
def img2char(imgobj):
width, heigth = (60, 60)
img_original = imgobj.resize((width, heigth))
img = imgobj.convert('L').resize((width, heigth))
# ma.imshow(img)
# ma.show()
ASCII_HIGH = '''$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. '''
img_new = Image.new('RGB', (width*12, heigth*15), 'white')
draw = ImageDraw.Draw(img_new)
txt=''
for y in range(heigth):
for x in range(width):
pos = (x, y)
gray = img.getpixel(pos)
index = int(gray/256*60)
txt = ASCII_HIGH[index]+' '
color = img_original.getpixel(pos)
draw.text((x*12, y*15), txt, fill=color)
return img_new.resize((width*12, width*12))
def gif2char(imgfile):
img=Image.open(imgfile)
frames=ImageSequence.Iterator(img)
img_colorchars=[]
for frame in frames:
colorchar=img2char(frame)
img_colorchars.append(colorchar)
img_colorchars[0].save('bcm_colorchar.gif',
append_images=img_colorchars[1:],
save_all=True,
loop=0,
duration=0.1)
gif2char('bcm.gif')
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn