2

I've found this page on the imagemagick forum: Merging 2 gifs, one is animated and transparent which links to the imagemagick docs on Animation Modification; specifically, the example here:

  convert canvas_prev.gif -coalesce \
          -gravity NorthEast  -draw 'image over 5,5 0,0 "rose:"' \
          -layers Optimize   draw_over.gif

Here's my attempt. I have these two gifs (i might be feeling a little morbid). The white in the first is actually transparent.

enter image description here

enter image description here

when I run

convert eyes.gif -coalesce -draw ' image over 0,0 0,0 "trump.gif" ' combine.gif

I get this:

enter image description here

which is not the complete effect I desire. The trump animation is no longer playing at all.

I want to see something more like this (this is created in Phaser JS, but this gives me no way to export the result as a new image other than manually recording a screencast):

enter image description here

max pleaner
  • 26,189
  • 9
  • 66
  • 118

1 Answers1

2

One way to do it, yet not sure if it's the best, is as follows:

  1. convert both animations into sprite-sheets of same dimensions
  2. paste one image over the another
  3. cut result into smaller frames and convert it into animated GIF

The commands should look like this:

montage -background none t.gif -tile x1@ -geometry +0+0 tt.png
montage e.gif[0-16,0-9] -tile x1@ -geometry +0+0 ee.png
magick convert -delay 10 -loop 0 ee.png tt.png -coalesce -flatten \
        -crop 150x150 +repage output.gif

Tricky part is the second line with eyes image. It has only 17 frames while skull has 27. So the sprite sheet size must be adjusted.

I works, however I am not quite happy with this as solution requires manual entering of some parameters (frames selection and output image dimensions).

rostok
  • 2,057
  • 2
  • 18
  • 20
  • I can programmatically get the number of frames given the code from [this question](http://stackoverflow.com/questions/20530417/imagemafick-identify-reports-incorrect-gif-frame-count) and I will know the dimensions, so this should be usable for my application. Although since you think there might be a better way, I'll leave the answer unaccepted for a bit. – max pleaner Apr 06 '17 at 16:58