魔杖创建空帧和不规则帧速率 [英] Wand creates empty frame and irregular frame rate

查看:169
本文介绍了魔杖创建空帧和不规则帧速率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下片段创建一个gif。此代码段源自提示,不要与此问题混淆。



更新1:

如果我创建没有预定义大小的wand对象,则输出如下。动画似乎没问题,但画布是第一个序列(更小),所以最终的gif被裁剪,现在完全显示第二个序列。

  #wand = Image2(width = 205,height = 223) 
wand = Image2()

更新2:

如果有上述变化,下面是输出,我也反过来输入序列,这样现在魔杖将采用第一个序列大小。现在最终的gif大小还可以,但正如你所看到的,更大的框架总是停留在后台,现在是新问题。

  #create frames 
for each_frame in reversed(self。 _tree_dot_frames):
img = Image2(blob = each_frame)
print('Image width:{} height:{}'。format(img.width,img.height))
wand。 sequence.append(img)

请帮忙,因为如果按上述任何一个方向行驶,我会陷入困境。



所需的解决方案将采用最大尺寸的馈送帧,并适应该尺寸的所有帧/下面应该做的事情(I在上面的问题中只显示了前2帧的数据)



解决方案

根据解决方案中给出的提示这里,我提出了以下修改过的片段,似乎解决了这个问题。显然我的要求需要 MagickSetImageDispose MagickExtentImage 这些尚未在魔杖中实现。我非常感谢 emcconville 提供此帮助,并要求他添加他的评论,如果需要以下解决方案。我还在探索。如果有任何关于这个问题的进一步问题,我会回来。

  def render(self):

wand = Image2()

#get max frame height,width
frameSizeList = []
tempImgList = []
for self__tree_dot_frames:
img = Image2(blob = each_frame)
frameSizeList.append((img.width,img.height))
tempImgList.append(img)
optimalFrameSize =(max(frameSizeList) ,key = itemgetter(1)))
#print('检测到最大帧大小:',optimalFrameSize)

#create frames
temp_mgList中的each_frame:
newImg = Image2(width = optimalFrameSize [0],height = optimalFrameSize [1],background = Color('WHITE'))
newImg.composite(each_frame,0,0)
wand.sequence.append (newImg)

#set frame rate
for cursor in range(len(self._tree_dot_frames)):
with wand.sequence [cursor] as frame:
打印('sequence width:{} height:{}'。format(frame.width,frame.height))
frame.delay = 100

#wand.merge_layers('merge')
wand.format ='gif'
wand.save(filename ='animated.gif')
print('no of frames:{} gif width:{} height:{}' .format(len(wand.sequence),wand.width,wand.height))
self._tree_dot_blob = wand.make_blob()

返回self._tree_dot_blob


I have below snippet which creates a gif. This snippet is derived from hints here. The snippet creates an empty frame and frames have irregular delay between them. Notice delay between nothingness and first frame, and then second frame quickly appears. Why this happens?

I had to create Image of particular size before hand because, wand is not resizing canvas according to maximum sized sequence. I have to find a way to sort that out as well.

def render(self):

        # map anim gif
        wand = Image2(width=205,height=223)

        #create frames
        for each_frame in self._tree_dot_frames:
            img = Image2(blob=each_frame)
            print('Image width: {} height: {}'.format(img.width,img.height))
            wand.sequence.append(img)

        #set frame rate
        for cursor in range(len(self._tree_dot_frames)):
            with wand.sequence[cursor] as frame:
                print('sequence width: {} height: {}'.format(frame.width,frame.height))
                frame.delay = 100

        #wand.merge_layers('merge')
        wand.format = 'gif'
        wand.save(filename='animated.gif')
        print('No of frames: {} gif width: {} height: {}'.format(len(wand.sequence),wand.width,wand.height))
        self._tree_dot_blob = wand.make_blob()

        return self._tree_dot_blob

Output:
Image width: 175 height: 136
Image width: 205 height: 223
sequence width: 205 height: 223
sequence width: 175 height: 136
No of frames: 3 gif width: 205 height: 223

PS: I have another issue with similar snippet here, not to be confused with this issue.

Update 1:
Below is the output if I create wand object without predefined size. The animation seems ok, but canvas is of first sequence (which is smaller), so final gif is cropped, now showing 2nd sequence fully.

    #wand = Image2(width=205,height=223) 
    wand = Image2()

Update 2:
Below is the output if with above change, I also feed the sequence in reverse so that now wand would take 1st sequence size. Now final gif size is ok, but as you can see, the bigger frame is always staying in background which is now the new problem.

    #create frames
    for each_frame in reversed(self._tree_dot_frames):
        img = Image2(blob=each_frame)
        print('Image width: {} height: {}'.format(img.width,img.height))
        wand.sequence.append(img)

Kindly help as I am getting stuck if going in any of above directions.

Desired solution would be one which takes max size of fed frames, and accommodates all frames in that size / something like below should do (I have shown only 1st 2 frames data in problem above)

解决方案

As per hints given in solution here, I came up with below modified snippet which seems to solve the issue. Apparantly my requirement requires MagickSetImageDispose or MagickExtentImage which are not yet implemented in wand. I am very thank ful to emcconville for this help and request him to add his comments if any needed for below solution. I am still exploring. In case of any further issue on this problem, I will get back.

def render(self):

    wand = Image2()        

    #get max frame height, width
    frameSizeList = []
    tempImgList = []
    for each_frame in self._tree_dot_frames:
        img = Image2(blob=each_frame)
        frameSizeList.append((img.width,img.height))
        tempImgList.append(img)
    optimalFrameSize = (max(frameSizeList,key=itemgetter(1)))
    #print('Max Frame size detected: ',optimalFrameSize)

    #create frames
    for each_frame in tempImgList:
        newImg = Image2(width=optimalFrameSize[0], height=optimalFrameSize[1], background=Color('WHITE'))
        newImg.composite(each_frame,0,0)
        wand.sequence.append(newImg)

    #set frame rate
    for cursor in range(len(self._tree_dot_frames)):
        with wand.sequence[cursor] as frame:
            print('sequence width: {} height: {}'.format(frame.width,frame.height))
            frame.delay = 100

    #wand.merge_layers('merge')
    wand.format = 'gif'
    wand.save(filename='animated.gif')
    print('No of frames: {} gif width: {} height: {}'.format(len(wand.sequence),wand.width,wand.height))
    self._tree_dot_blob = wand.make_blob()

    return self._tree_dot_blob

这篇关于魔杖创建空帧和不规则帧速率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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