问题描述
我正在尝试使用 Wand 制作液体重新缩放的 gif,但是当将 gif 保存到文件中时,文件大小很淫秽巨大,我的意思是,来自 1539x2048 和 242 的 JPG 图像KB 它产生 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()
时引发分段错误。
欢迎任何帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)