2016-04-25 8 views
1

を組み立てるだから私は(透明PNG画像のシリーズを持っているし、新しいイメージにそれらを追加)杖:どのように透明GIF /クリア背景に、各フレーム

新しい残念ながら背景は、「クリア」されていません
with Image() as new_gif: 
    for img_path in input_images: 
     with Image(filename=img_path) as inimg: 
      # create temp image with transparent background to composite 
      with Image(width=inimg.width, height=inimg.height, background=None) as new_img: 
       new_img.composite(inimg, 0, 0) 
       new_gif.sequence.append(new_img) 
    new_gif.save(filename=output_path) 

画像が追加されます。彼らはそこにも最後の画像があります:

enter image description here

をしかし、どのように、私は、バックグラウンドをクリアするのですか?私はちょうどそれを新しい画像の前部に合成することで、まさにそれを行います。ハーフ!!

コマンドラインImageMagickにはsimilarというものがありますが、ワンドにはそのようなものはありません。これまでは、適切な背景色で回避する必要がありました。

答えて

2

ソースイメージが表示されていない場合、私は-set dispose backgroundが必要であると仮定できます。 の場合は、wand.api.library.MagickSetOptionメソッドに電話する必要があります。

from wand.image import Image 
from wand.api import library 

with Image() as new_gif: 
    # Tell new gif how to manage background 
    library.MagickSetOption(new_gif.wand, 'dispose', 'background') 
    for img_path in input_images: 
     library.MagickReadImage(new_gif.wand, img_path) 
    new_gif.save(filename=output_path) 

Assembled transparent GIF

または代わりに...

次のことができます背景の廃棄の動作を管理するためのエクステント杖。この方法は、各フレームをプログラム的に変更/生成する利点があります。しかし、ダウンサイドには、でさらに多くの作業が含まれます。例えば。

import ctypes 
from wand.image import Image 
from wand.api import library 

# Tell python about library method 
library.MagickSetImageDispose.argtypes = [ctypes.c_void_p, # Wand 
              ctypes.c_int] # DisposeType 
# Define enum DisposeType 
BackgroundDispose = ctypes.c_int(2) 
with Image() as new_gif: 
    for img_path in input_images: 
     with Image(filename=img_path) as inimg: 
      # create temp image with transparent background to composite 
      with Image(width=inimg.width, height=inimg.height, background=None) as new_img: 
       new_img.composite(inimg, 0, 0) 
       library.MagickSetImageDispose(new_img.wand, BackgroundDispose) 
       new_gif.sequence.append(new_img) 
    # Also rebuild loop and delay as ``new_gif`` never had this defined. 
    new_gif.save(filename=output_path) 

With MagickSetImageDispose <は - まだ

+0

うーんが動作しない遅延補正を必要とします。私は元の画像を削除したと思う:/しかし、あなたが** xnviewを使って投稿した画像を見た場合、例えばShift + PgDown/PgUp **を1歩進んで実際にトレイルなしで保存されていることがわかる!!私は最初に、どのようにそれらがどのようにレンダリングされているのではないかということについて考えました... – ewerybody

+0

もちろん、それはコマンドラインimageMagickと '-dispose background'で動作します。しまった。私はそれが素敵でpythonicであることを望んでいた...:| – ewerybody

+0

ああ!わかった。私たちはC-APIを通じて直接アニメーションを構築する必要があります – emcconville

関連する問題