擅长:python、mysql、java
<p>作为我另一个答案的替代方案,您也可以只<strong><a href="https://pillow.readthedocs.io/en/5.1.x/handbook/image-file-formats.html#saving" rel="nofollow noreferrer">set the ^{<cd1>} value to 2</a></strong>:</p>
<pre><code>im1.save('output.gif', save_all=True, append_images=[im2, im1, im2],
loop=0, duration=200, transparency=255, disposal=2)
</code></pre>
<p>请注意,与我的其他答案不同,这并不是100%都有效,因为透明度通道可以跳转到其他索引。:/然而,这似乎只发生在有许多颜色的较长GIF中</p>
<p>左:此答案,右:手动对齐的其他答案</p>
<p><a href="https://i.stack.imgur.com/YtEbp.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YtEbp.gif" alt="example of bug persisting"/></a><a href="https://i.stack.imgur.com/dVGEB.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dVGEB.gif" alt="example of bug fixed"/></a></p>
<p>编辑:<a href="https://github.com/python-pillow/Pillow/issues/1976#issuecomment-800854435" rel="nofollow noreferrer">Here</a>据称这在新版枕头中得到了<strong>修复!(我认为是8.1.2+)</p>