如何使用Python将WebP图像转换为Gif?

Azi*_*tov 5 python gif python-imaging-library webp

我已经尝试过这个:

from PIL import Image
im = Image.open('this.webp')
im.save('that.gif', 'gif', save_all=True)
Run Code Online (Sandbox Code Playgroud)

这给了我这个错误

类型错误:& 不支持的操作数类型:“tuple”和“int”

我的网站上有数百张 webp 图像,需要将它们转换为 gif,因为 Firefox 不支持它。谢谢。

mur*_*zel 8

保存前将背景设置为“无”。

from PIL import Image
im = Image.open('this.webp')
im.info.pop('background', None)
im.save('that.gif', 'gif', save_all=True)
Run Code Online (Sandbox Code Playgroud)

感谢:https://github.com/python-pillow/Pillow/issues/2949#issuecomment-419422861

  • @穆拉特戈泽尔谢谢!还要考虑通过设置这些额外选项来获得更好的转换质量的可能性:`im.save(str(sys.argv[1]).replace('webp','gif'), 'gif', save_all=True ,无损=真,质量=100,方法=6)`。文档[此处](https://pillow.readthedocs.io/en/latest/handbook/image-file-formats.html#webp) (2认同)