PIL在gif中显示所有先前的帧 [英] PIL is showing all the previous frames in the gif

查看:47
本文介绍了PIL在gif中显示所有先前的帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pillow version:5.4.1

问题是我可以看到gif中的所有帧.

The problem is I can see all the frames in the gif.

期望:在具有5帧的gif的生命周期中,每帧应在一段时间内可见,而在gif结束时,仅第5帧应可见.

Expectation: in the lifecycle of a gif having 5 frames each frames should be visible for a fraction of time and at the end of gif only 5th frame should be visible.

实际:在gif末尾,我可以看到所有帧1-2-3-4-5.

Actual: In my case at the end of the gif I can see all the frames 1-2-3-4-5.

gif动画中有5帧,所有帧均为gif格式(静态),我也尝试过使用png文件,但是得到的结果相同.

There are 5 frames in the gif animation and all the frames are in gif format(static) I also tried with png files too but I am getting the same result.

我所有的相框都是透明的背景.

All my frames are with transparent background.

from PIL import Image

frame_list = []
frame_list.append("object_1.gif")
frame_list.append("object_2.gif")
frame_list.append("object_3.gif")
frame_list.append("object_4.gif")
frame_list.append("object_5.gif")

images = []
for n in frame_list:
    frame = Image.open(n)
    images.append(frame)

images[0].save('anitest.gif',
               save_all=True,
               format='GIF',
               append_images=images[1:],
               duration=200,
               loop=0)

如果有人遇到相同的问题,请告诉我我做错了什么事

If anyone encountered the same issue please let me know what am I doing wrong?

使用imageio的以下代码可以正常工作,但是我失去了透明性,并且比较PIL的速度很慢

images = []
for filename in names:
    images.append(imageio.imread(filename))
imageio.mimsave('anitest.gif', images,duration=0.3)

推荐答案

我认为处置" 设置不正确.尝试:

I think the "disposal" is not being set correctly. Try with:

images[0].save('anitest.gif',
               save_all=True,
               format='GIF',
               append_images=images[1:],
               duration=200,disposal=2,
               loop=0)

这篇关于PIL在gif中显示所有先前的帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆