1

有谁知道怎么做?我尝试使用 PIL、apng 和 imageio,但没有成功。

4

1 回答 1

1

您还可以使用“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"。在某些情况下,可能需要在管理员模式下运行控制台。

于 2021-01-13T11:49:27.007 回答