有谁知道怎么做吗?我尝试使用PIL、apng和imageio,但都不起作用。
发布于 2021-01-13 19:49:27
您也可以使用'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"
方式安装库。在某些情况下,可能需要在管理员模式下运行控制台。
https://stackoverflow.com/questions/51696097
复制相似问题