python-3.x - 使用 Python 图像库 (PIL) 保存 gif 图像时动画 GIF 图像像素化
问题描述
我正在尝试在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)
解决方案
解决它!
解决方法可以不使用 PIL 传递动画图像,而是直接使用context manager
.
if image.is_animated:
with open(media_location, 'wb') as fp:
fp.write(byte_stream)
推荐阅读
- opencv - 使用 canny 和 hough 变换检测图像是否像素化
- ios - 数据传递问题
- amazon-web-services - route53 域名未与我的 ec2 弹性 ip 连接
- polly - 我可以在构建后修改策略吗?
- stata - 标记化解析选项
- reactjs - 如何从 React 中的子组件更新父状态 + 发送参数
- javascript - 使用 JavaScript 突出显示当前页面
- swift - 为什么 Swift 在 for-in 循环中使用下标语法比使用直接访问元素更快?
- c++ - 如何更改 c++ 文件的 mach-o 可执行文件的入口点?
- codenameone - 在有/没有互联网的情况下为 OfflineCommand 按顺序或随机顺序生成数字