Resizing GIFs with Wand + ImageMagick

笑着哭i 提交于 2019-12-31 02:31:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/23016158/resizing-gifs-with-wand-imagemagick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!