微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 python Wand 制作 gif 时文件大小很大

如何解决使用 python Wand 制作 gif 时文件大小很大

我正在尝试使用 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 举报,一经查实,本站将立刻删除。