所以这个GIF在打开之前看起来非常好:
但是,当使用枕头打开使用
imageObject = Image.open(path.join(petGifs, f"{pokemonName}.gif"))
它会出错,添加各种颜色与源图像相似的框。这是一个示例帧,但几乎每一帧都是不同的,它位于不同的位置,具体取决于GIF:
唯一能解决这个问题的是ezgif的unoptimize选项(在它们的optimize page中找到)。但是,我需要在每个GIF上都这样做,而且有很多
我需要一种批量未优化的方法,或者一种在Python中打开GIF的新方法(目前使用的是Pillow),这将解决这个问题
至少对于提取适当的单帧,可能有一个解决方案
所有帧(第一帧除外)的^{} 方法设置为
2
,即“恢复到背景色”浏览Pillow的源代码,您将找到相应的line where the disposal method ^{} is considered ,在下面,您将发现:
如果您检查有故障的帧,您会注意到不需要的框的深绿色位于调色板的
0
位置。因此,似乎选择了错误的颜色进行处理,因为–我不知道为什么–选择了上面的else
案例,而不是使用透明度信息–应该在那里那么,让我们忽略可能有问题的东西:
提取的帧如下所示:
这对我来说很好
如果碰巧,透明度信息实际上设置为
0
,那么这里不应该做任何伤害,因为我们(重新)设置了仍然正确的透明度信息我不知道(重新)保存到GIF是否有效,因为帧现在处于
RGBA
模式,从那里保存到GIF也很棘手您可以尝试使用:
相关问题 更多 >
编程相关推荐