无聊时第一生产力,首先时因为我看见了一张比较有意思的图片~
IMG_5551(20200911-160010).JPG
之后,我又看到了这个动图:
IMG_5552.GIF
随后,我就有了以下的想法:
import imageio
from PIL import Image, ImageDraw, ImageFont
import numpy as np
image_list = imageio.mimread(r'C:\Users\CaiNanDangDao\Desktop\IMG_5552.GIF')
# print(img_list)
font = ImageFont.truetype('simfang',size=20)
# 字体颜色
fillColor = (255,0,255)
# 文字输出位置
position = (20,20)
# 输出内容
str_ = '女人--只会影像我拔剑的速度~'
str_ = str_.encode('utf-8').decode('utf-8')
print(len(str_))
# draw = ImageDraw.Draw(img_PIL)
# draw.text(position, str, font=font, fill=fillColor)
result_list = []
print(len(image_list))
for index, image_ in enumerate(image_list):
image_ = Image.fromarray(image_)
if index <= 15:
temp_draw = ImageDraw.Draw(image_)
temp_draw.text(position, str_[:index], font=font, fill=fillColor)
else:
temp_draw = ImageDraw.Draw(image_)
temp_draw.text(position, str_, font=font, fill=fillColor)
image_ = np.asarray(image_)
result_list.append(image_)
imageio.mimsave('./test.gif', np.array(result_list))
ps: 这里面有个坑点,就是需要查windows字体的中英文对照表~
最后的效果:
test.gif
网友评论