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



有人知道怎么做吗?我试过使用PIL、apng和imageio,但都没用。

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

相关内容

  • 没有找到相关文章

最新更新