python - 使用 python Wand 制作 gif 时文件大小很大
问题描述
我正在尝试使用 Wand 进行液体重新缩放的 gif,但是当将 gif 保存到文件中时,文件大小非常大,我的意思是,从 1539x2048 和 242 KB 的 JPG 图像会产生55 MB的 gif 。此外,调用image.make_blob()
时生成 blob 需要很长时间。
from wand.image import Image
def gifynize(image: str, level: int = 50) -> bytes:
with Image() as gif:
with Image(filename=image) as source:
width, height = source.width, source.height
target_witdh = width * (100 - level) // 100
target_height = height * (100 - level) // 100
width_steps = (width - target_x) // (10 * 3)
height_steps = (height - target_y) // (10 * 3)
with source.clone() as clone:
gif.sequence.append(clone)
for _width, _height in zip(
range(width, target_width, -width_steps), range(heigth, target_heigth, -heigth_steps)
):
source.liquid_rescale(_width, height)
with source.clone() as clone:
clone.resize(width, height) # Bring back to the original size
gif.sequence.append(clone)
gif.format = "gif"
return gif.make_blob()
我试过了gif.type = "optimize"
,gif.optimize_layers()
但gif.optimize_transparency()
最终的 gif 文件大小没有改变。此外,当使用重图像 (2 MB) 时,它会在调用img.make_blob()
.
欢迎任何帮助。
解决方案
推荐阅读
- spring - Spring Rest API 返回实体/对象与 joda 本地日期、本地时间、日期时间应显示格式化的日期或时间
- reactjs - 反应热加载器:
不支持动态更改`store` - typescript - 打字稿项目中的单元测试目标
- apache-kafka - kafka.common.OffsetOutOfRangeException
- php - Laravel Beyondcode websockets不连接
- laravel - 如何在发送第二封电子邮件之前检查该电子邮件是否已被客人确认
- javascript - Webpack 没有为 request 做定义
- grpc - 跟踪 grpc 服务器中的请求队列
- python - 使用 Python 将文件导入和保存到 NOSQL 数据库
- vba - 我是否需要 Microsoft 开发人员版工具许可证才能在 Office 2000 到 Office 2007 中的 VBA 中编码?