Python-136 制作gif动画图并保存 2021-12-2

2021-12-28  本文已影响0人  RashidinAbdu
#pip install matplotlib
#pip install pillow
import matplotlib.pyplot as plt
import matplotlib.animation as anim
from PIL import Image
from glob import glob
from matplotlib import animation

fig, ax = plt.subplots(figsize=(3.6, 3.5))
fig.subplots_adjust(bottom=0, top=1, left=0, right=1)
ax.axis('off')

ims = []
for fname in sorted(glob('C:/Users/Rashidin Abdugheni/Pictures/wallpaper/simba.jpg')):
# print(fname) # uncomment to follow loading of images
           im = ax.imshow(Image.open(fname), animated=True)
           ims.append([im])

ani = anim.ArtistAnimation(fig, artists=ims, interval=113,repeat=True)
# Uncomment to save as mp4 movie file. Need ffmpeg.
# ani.save('pacb.mp4', writer='ffmpeg') # ffmpeg
plt.show()
ani.save('C:/Users/Rashidin Abdugheni/Pictures/wallpaper/Animation.gif', writer='pillow')

得到的是:


Animation.gif
上一篇下一篇

猜你喜欢

热点阅读