私信  •  关注

Daniel McGrath

Daniel McGrath 最近创建的主题
Daniel McGrath 最近回复了
5 年前
回复了 Daniel McGrath 创建的主题 » 在Python中将png文件转换为动画gif

有效的解决方案

迄今为止其他解决办法的问题:
(一)
2个) 没有解决无序目录迭代的方法,这对于GIFs是必不可少的
三) 没有解释如何为python 3安装imageio

按如下方式安装imageio: python3-m pip安装imageio

注: 您需要确保您的帧在文件名中有某种索引,以便对它们进行排序,否则您将无法知道GIF的开始或结束位置

import imageio
import os

path = '/Users/myusername/Desktop/Pics/' # on Mac: right click on a folder, hold down option, and click "copy as pathname"

image_folder = os.fsencode(path)

filenames = []

for file in os.listdir(image_folder):
    filename = os.fsdecode(file)
    if filename.endswith( ('.jpeg', '.png', '.gif') ):
        filenames.append(filename)

filenames.sort() # this iteration technique has no built in order, so sort the frames

images = list(map(lambda filename: imageio.imread(filename), filenames))

imageio.mimsave(os.path.join('movie.gif'), images, duration = 0.04) # modify duration as needed
14 年前
回复了 Daniel McGrath 创建的主题 » 如何使用jquery、javascript和html动态设置下拉列表的所选选项?

请原谅我的无知,但你为什么要用 $('.salesperson') 而不是 $('#salesperson') 处理身份证时?