简体   繁体   English

使用Wand + ImageMagick调整GIF大小

[英]Resizing GIFs with Wand + ImageMagick

I am using Wand 0.3.7 with ImageMagick 6.8.8-10 to batch-resize some animated GIF files I have. 我使用Wand 0.3.7ImageMagick 6.8.8-10批量调整我的一些动画GIF文件。 But for some reason, Wand only resizes one frame in the image, leaving the others at their original size. 但由于某种原因,Wand只调整图像中的一帧,使其他帧保持原始大小。

Here is the original image I am trying to resize: 这是我想要调整大小的原始图像:

原始图像

And here is the output from Wand: 这是Wand的输出:

用魔杖调整大小

If I use ImageMagick from the command line directly (following instructions from here ), the GIF is correctly resized, as expected: 如果我直接从命令行使用ImageMagick(按照此处的说明),GIF会按预期正确调整大小:

使用ImageMagick调整大小

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: 您可以尝试打开一个新的目标Image并将每一帧循环到其中:

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. 适合我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM