挑帧

"""
   挑帧,本程序把一个较大的gif文件,删除大部分帧,保留'关键帧'以减小gif文件尺寸。
   经证明用imageio合并的gif文件仍较大,可以用其它软件如gifanimator打开后另存为
   就更小了。关键词:拆帧/合帧/合并帧
"""
import os
import imageio
from PIL import Image,ImageSequence

def makegif(path,filename):
   """把png文件合成gif文件"""
   images = []
   amount = len(os.listdir(path))   
   for i in range(amount):
       file = path + os.sep + str(i) + ".png"
       images.append(file)  
   frames = [imageio.imread(image) for image in images]
   imageio.mimsave(filename, frames, 'GIF', duration=0.5)

def pick_frame(inputgif,outgif,间隔数):
    """挑帧函数,遍历gif中的每一帧,挑些帧出来合成新的gif文件"""
    out_dir = 'out_dir'
    if os.path.exists(out_dir):
        for file in os.listdir(out_dir):
            os.remove(os.getcwd() + os.sep + out_dir + os.sep + file)
    else:
        os.mkdir(out_dir)
    

You must log in to read the rest of this article. Please log in or register as a user.