Search code examples
imagemagickgifanimated-gifimagemagick-convert

Wrap a gif with a png


There are two image, one is gif, another is png. Now I need to wrap the gif image with png image. I use ImageMagick and I think it may work for me.

convert src.png input.gif -gravity Center -composite des.gif;
  • As you see, the output is unexpected while there is a black block.
  • And the des.gif is not animated.

enter image description here

left is des.gif the right is input.gif

EDIT

Here is my test files. https://drive.google.com/drive/folders/0B-64AliLi9OnWVQyLWU3TElHNHM?usp=sharing


Solution

  • You have 77 frames. But the first frame is much smaller than all the rest. From Imagemagick (6.9.9.13 Q16 Mac OSX Sierra), I can see this from

    identify input.gif
    
    input.gif[0] GIF 216x384 216x384+0+0 8-bit sRGB 256c 3.20786MiB 0.010u 0:00.009
    
    input.gif[1] GIF 1080x1920 216x384+0+0 8-bit sRGB 64c 3.20786MiB 0.010u 0:00.009
    
    ...
    
    input.gif[76] GIF 1080x1920 216x384+0+0 8-bit sRGB 64c 3.20786MiB 0.000u 0:00.000
    

    Also all frames but the first are near solid green. Only the first has a circle in it.

    Nevertheless, if you fix your input.gif, you can composite them so all the gif frames animate over the background png using the following command:

    convert image.png null: \( input.gif -coalesce \) -gravity Center -layers composite des.gif
    

    Note that after the coalesce all frames become 216x384. That makes the overlay frames way too small. This will make all frames larger so that they fit the background. But still all will be green exact for the first.

    convert image.png null: \( input.gif -coalesce -resize 1080x1920! \) -gravity Center -layers composite des.gif
    

    See http://www.imagemagick.org/Usage/anim_mods/#background If using Imagemagick 7, then change convert to magick.