How do I create an animated gif in Python using Wand?

我怕爱的太早我们不能终老 提交于 2019-11-29 14:01:21

The best examples are located in the unit-tests shipped with the code. wand/tests/sequence_test.py for example.

For creating an animated gif with wand, remember to load the image into the sequence, and then set the additional delay/optimize handling after all frames are loaded.

from wand.image import Image

with Image() as wand:
    # Add new frames into sequance
    with Image(filename='1.png') as one:
        wand.sequence.append(one)
    with Image(filename='2.png') as two:
        wand.sequence.append(two)
    with Image(filename='3.png') as three:
        wand.sequence.append(three)
    # Create progressive delay for each frame
    for cursor in range(3):
        with wand.sequence[cursor] as frame:
            frame.delay = 10 * (cursor + 1)
    # Set layer type
    wand.type = 'optimize'
    wand.save(filename='animated.gif')

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