首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Python将动画PNG (APNG)转换为GIF

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

Stack Overflow用户
提问于 2018-08-06 00:16:44
回答 1查看 574关注 0票数 1

有谁知道怎么做吗?我尝试使用PIL、apng和imageio,但都不起作用。

EN

回答 1

Stack Overflow用户

发布于 2021-01-13 19:49:27

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

代码语言:javascript
运行
复制
#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"方式安装库。在某些情况下,可能需要在管理员模式下运行控制台。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51696097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档