【问题标题】:Converting a gif to webp in pillow saves the first frame only在枕头中将 gif 转换为 webp 仅保存第一帧
【发布时间】:2020-10-31 14:27:40
【问题描述】:

我正在尝试将 gif 转换为 webp,但它不再是动画,它只显示第一帧,如何解决这个问题? 这是我的代码:

def make_(image):
    im = Image.open(image)
    im_io = BytesIO()
    im.save(im_io, format='WEBP')
    
    name = image.name
    name = name.replace('.gif', '.webp')

    webp = InMemoryUploadedFile(im_io, 'ImageField', name, 'image/webp',sys.getsizeof(image), None)
    return webp

而且我不认为在name = name.replace('.gif', '.webp') 中用.webp 替换.gif 是最好的方法,所以如果你有任何建议可以在不使用os 的情况下解决这个问题。

谢谢

【问题讨论】:

    标签: python django python-imaging-library


    【解决方案1】:

    我在这里找到了解决方案https://github.com/python-pillow/Pillow/issues/4313 我不知道为什么,但这有效:

    im.save(im_io, format='WEBP', save_all=True)
    

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 2019-11-24
      • 2017-09-10
      • 2020-06-27
      • 2021-02-01
      • 2012-05-03
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多