0

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

 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)
4

1 回答 1

0

解决它!

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

    if image.is_animated:
        with open(media_location, 'wb') as fp:
            fp.write(byte_stream)
于 2020-05-15T10:02:26.660 回答