使用Python将动画PNG(APNG)转换为GIF

时间:2018-08-05 16:16:44

标签: python gif apng

有人有什么想法怎么做吗?我尝试使用PIL,apng和imageio,但是没有用。

1 个答案:

答案 0 :(得分:0)

您还可以使用“apnggif”库来读取动画 PNG (APNG) 并转换为 GIF 文件。

#Sample Python Code#

from apnggif import apnggif

# Here it reads files in the folder input and sorts
imgs = glob.glob("input/*.png")
imgs.sort(key=lambda f: int(re.sub('\D', '', f)))

# Folder Creation for the output
# Gets current working directory
path = os.getcwd()
# Joins the folder that we wanted to create
path = os.path.join(path, 'output') 
# creates the folder, and checks if it is created or not.
os.makedirs(path, exist_ok=True)

# Iterates over the input images and saves them into output folder
for idx, img in enumerate(imgs):
    filenamePath = "output\\" + str(idx+1) + ".gif"
    apnggif(img, filenamePath)

要使用它,您应该按如下方式安装库"pip install apnggif"。在某些情况下可能需要以管理员模式运行控制台。