框架不会在python魔杖中消失 [英] Frames not disappearing in python wand

查看:166
本文介绍了框架不会在python魔杖中消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据不会实现C-API方法 MagickSetImageDispose ,或 MagickExtentImage 这是我认为你需要的。尽管它很容易实现那些方法,你可能会陷入重建每个图像 - 逐帧。

 来自wand.image导入图像为图像2 
来自wand.color导入颜色
来自wand.compat导入嵌套

嵌套(Imag e2(),
Image2(filename ='d2.gif'),
Image2(filename ='d3.gif'))as(wand,one,two):
width = max (one.width,two.width)
height = max(one.height,two.height)
#使用Image2重建具有帧
的完整范围的图像(width = width,height = height,background = Color('WHITE'))as f1:
f1.composite(1,0,0)
wand.sequence.append(f1)
with Image2(width = width ,height = height,background = Color('WHITE'))as f2:
f2.composite(two,0,0)
wand.sequence.append(f2)
#Creite progressive每帧的延迟
为光标范围(2):
,wand.sequence [cursor]为帧:
frame.delay = 100
wand.type ='optimize'
wand.save(filename ='animated.gif')

原始答案不要使用!






你想打电话给 wand.image.Image.merge_layers 方法,而不是 wand.image.Image.type property。



试试跟随...

 将Image2()作为魔杖:
#将新的帧添加到sequance
中,Image2(blob = d2)为:
wand.sequence.append(one)
,Image2(blob = d3)为2:
wand.sequence.append(二)

#为每个帧创建渐进式延迟
为范围内的游标(2):
,wand.sequence [cursor]为frame:
frame.delay = 100
#设置图层类型
wand.merge_layers('optimize')#或'optimizeimage',或'composite'
wand.save(filename ='animated .gif')


As per hint from here, I tried to create a gif with 2 dissimilar images as below. It works, but one frame is not disappearing to show another frame. Why would this happen and how to rectify?

from wand.image import Image as Image2

with Image2() as wand:
    # Add new frames into sequance
    with Image2(blob=d2) as one:
        wand.sequence.append(one)
    with Image2(blob=d3) as two:
        wand.sequence.append(two)

    # Create progressive delay for each frame
    for cursor in range(2):
        with wand.sequence[cursor] as frame:
            frame.delay = 100
    # Set layer type
    wand.type = 'optimize'
    wand.save(filename='animated.gif')

display(Image('animated.gif'))

Current output:

解决方案

Updated answer

... I got error using that ...

Looks like hardcoded validation values does not allow this technique to be leveraged. This is a bug, and I'll submit a patch upstream.

@ -2548,7 +2548,7 @@ class BaseImage(Resource):
         .. versionadded:: 0.4.3

         """
-        if method not in ['merge', 'flatten', 'mosaic']:
+        if method not in IMAGE_LAYER_METHOD:
             raise TypeError('method must be one of: merge, flatten, mosaic')

Currently, doesn't implement the C-API methods MagickSetImageDispose, or MagickExtentImage which is what I believe you need. Although it's fairly easy to implement those methods, you may be stuck with rebuilding each image - frame-by-frame.

from wand.image import Image as Image2
from wand.color import Color
from wand.compat import nested

with nested(Image2(),
            Image2(filename='d2.gif'),
            Image2(filename='d3.gif')) as (wand, one, two):
    width = max(one.width, two.width)
    height = max(one.height, two.height)
    # Rebuild images with full extent of frame
    with Image2(width=width, height=height, background=Color('WHITE')) as f1:
        f1.composite(one, 0, 0)
        wand.sequence.append(f1)
    with Image2(width=width, height=height, background=Color('WHITE')) as f2:
        f2.composite(two, 0, 0)
        wand.sequence.append(f2)
    # Create progressive delay for each frame
    for cursor in range(2):
        with wand.sequence[cursor] as frame:
            frame.delay = 100
    wand.type = 'optimize'
    wand.save(filename='animated.gif')

Original answer DO NOT USE!


You want to call wand.image.Image.merge_layers method, not wand.image.Image.type property.

Try the following...

with Image2() as wand:
    # Add new frames into sequance
    with Image2(blob=d2) as one:
        wand.sequence.append(one)
    with Image2(blob=d3) as two:
        wand.sequence.append(two)

    # Create progressive delay for each frame
    for cursor in range(2):
        with wand.sequence[cursor] as frame:
            frame.delay = 100
    # Set layer type
    wand.merge_layers('optimize')  # or 'optimizeimage', or 'composite'
    wand.save(filename='animated.gif')

这篇关于框架不会在python魔杖中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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