使用 Wand + ImageMagick 调整 GIF 大小 [英] Resizing GIFs with Wand + ImageMagick

查看:44
本文介绍了使用 Wand + ImageMagick 调整 GIF 大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ),GIF 已按预期正确调整大小:

这是我目前调整图像大小的方式:

用 Image(filename="src.gif") 作为 img:img.resize(50, 50)img.save("dest.gif")

我还尝试遍历每一帧并单独调整它们的大小:

用 Image(filename="src.gif") 作为 img:对于 img.sequence 中的帧:frame.resize(50, 50)frame.destroy()img.save("dest.gif")

两者都产生与上面相同的结果.我做错了什么?

解决方案

您可以尝试打开一个新的目标 Image 并将每一帧循环到其中:

 with Image() as dst_image:使用 Image(filename=src_path) 作为 src_image:对于 src_image.sequence 中的帧:frame.resize(x, y)dst_image.sequence.append(frame)dst_image.save(文件名=dst_path)

对我有用.

I am using Wand 0.3.7 with ImageMagick 6.8.8-10 to batch-resize some animated GIF files I have. But for some reason, Wand only resizes one frame in the image, leaving the others at their original size.

Here is the original image I am trying to resize:

And here is the output from Wand:

If I use ImageMagick from the command line directly (following instructions from here), the GIF is correctly resized, as expected:

This is how I am currently resizing the image:

with Image(filename="src.gif") as img:
    img.resize(50, 50)
    img.save("dest.gif")

I have also tried iterating through each frame and resizing them individually:

with Image(filename="src.gif") as img:
    for frame in img.sequence:
        frame.resize(50, 50)
        frame.destroy()
    img.save("dest.gif")

Both produce the same result seen above. What am I doing wrong?

解决方案

You might try opening a new target Image and loop every frame into that:

with Image() as dst_image:
    with Image(filename=src_path) as src_image:
        for frame in src_image.sequence:
            frame.resize(x, y)
            dst_image.sequence.append(frame)
    dst_image.save(filename=dst_path)

works for me.

这篇关于使用 Wand + ImageMagick 调整 GIF 大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆