将gif分解成单个图片

  import os

  from PIL import Image,ImageSequence

  gif = Image.open(r'LDY00.gif')

  if os.path.exists("output1") == False:

  os.mkdir("output1")

  for i,frame in enumerate(ImageSequence.Iterator(gif),1):

  frame.save(r'output1/%d.png'%i)

  将单张图片合成gif,

  import imageio

  def create_gif(path, gif_name, duration):

  frames = []

  image_list = []

  for i in range(1,60):

  image_list.append(path+"/%d.png" % i)

  for image_name in image_list:

  frames.append(imageio.imread(image_name))

  imageio.mimsave(gif_name, frames, 'GIF', duration=duration)

  return郑州中原妇科医院 http://mobile.chfk120.com/

  def main():

  #image_list = ['output1/1.png', 'output1/2.png', 'output1/3.png']

  path=r'output1'

  gif_name = 'output1/Dec02.gif'

  duration = 2

  create_gif(path, gif_name, duration)

  if __name__ == '__main__':

  main()