【问题标题】:Animated GIF images getting pixelated when saving gif image with Python Image Library(PIL)使用 Python 图像库 (PIL) 保存 gif 图像时动画 GIF 图像像素化
【发布时间】:2020-08-30 14:56:15
【问题描述】:

我正在尝试在Hug/python 中创建一个图像上传实用程序,并希望保存图像和 gif。但是在上传一些 gif 图像时,gif 图像似乎有很多像素化。下面给出的是我在上传实用程序中使用的代码 sn-p。

 image = Image.open(io.BytesIO(file))
 frames = [frame.copy() for frame in ImageSequence.Iterator(image)]
 image.save(media_location, save_all=True, append_images=frames)

【问题讨论】:

    标签: python-3.x file-upload python-imaging-library animated-gif hug


    【解决方案1】:

    修好了!

    解决方法可以不使用 PIL 传递动画图像,而是直接使用 context manager 存储它。

        if image.is_animated:
            with open(media_location, 'wb') as fp:
                fp.write(byte_stream)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-04
      • 2019-08-11
      • 2011-01-09
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      • 2012-02-26
      相关资源
      最近更新 更多