首页样式没调好明天再更新:分享两个脚本gif转字符gif和gif倒放(忘了从哪抄的了),以后可以找时间加到django项目里面通过页面上传gif返回字符gif或者倒放。
代码语言:javascript复制import imageio
import cv2
yuanpic='F:workspacepythonWorkMyPythonpicture可达鸭.gif'
dealPic='F:workspacepythonWorkMyPythonpicture字符可达鸭.gif'
string ="$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_ ~<>i!lI;:,"^`'. " #灰度与字符的映射
pics = imageio. mimread(yuanpic) #读取动态图,把动态图转化为一帧一帧的图片
A=[]
#把上面的每帧图片转化成为字符画,并保存在A中
for img in pics:
u,v,_=img.shape
c= img * 0 255
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
for i in range(0,u,4):
for j in range(0,v,4):
pix
= gray[i, j]
b, g, r, _ = img[i, j]
zifu = string[int(((len(string) - 1) * pix) / 256)]
cv2.putText(c, zifu, (j, i), cv2.FONT_HERSHEY_COMPLEX,0.5, (int(b), int(g), int(r)), 1)
A.append(c)
imageio.mimsave(dealPic, A, 'GIF', duration=0.1) # 把A列表里的字符画组合起来,变成动态图
print('转化完成,请到你保存的路径下查看')
quit(0)