Page 1 of 1

Overlay an image onto a gif, for a certain number of frames?

Posted: 2013-09-11T15:16:03-07:00
by xereeto
Hi,

Normally if I want to add an overlay to a gif, I'd use

Code: Select all

convert animation.gif -coalesce -geometry +0+0 null: overlay.png -layers composite -layers optimize animation_with_overlay.gif
But is there a way to add a different overlay per frame, without splitting the gif up?

For example:

overlay1.png frames 1-12

overlay2.png frames 13-24

overlay3.png frames 25-36

Is that possible with imagemagick?

Thank you!

Re: Overlay an image onto a gif, for a certain number of fra

Posted: 2013-09-11T15:33:59-07:00
by fmw42
I do not think that is possible. My understanding is that you would have to coalesce groups of frames and then process each set separately and then put them all back together in a animation. However, I will defer to anyone else who has a better way.

I suspect you can do some thing like

convert animation.gif[0-11] -coalesce -geometry +0+0 null: overlay1.png -layers composite -layers optimize animation_with_overlay1.gif
convert animation.gif[12-23] -coalesce -geometry +0+0 null: overlay2.png -layers composite -layers optimize animation_with_overlay2.gif
...

then

convert animation_with_overlay1.gif animation_with_overlay2.gif -coalesce -layers optimize final_animation.gif

I am not sure if -coalesce or -layers optimize is needed for the last command.

In the first sequence of commands you might want to save the results to miff format for quality and then convert to gif at the end when you have each set of miff files.

Re: Overlay an image onto a gif, for a certain number of fra

Posted: 2013-09-11T15:41:48-07:00
by snibgo
A single command is possible, something like this (Windows) script:

Code: Select all

convert ^
  animation.gif[0-11] -coalesce null: overlay1.png -layers composite ^
  ( animation.gif[1-23] -coalesce null: overlay2.png -layers composite ) ^
  ( animation.gif[24-35] -coalesce null: overlay3.png -layers composite ) ^
  -layers optimize o.gif

Re: Overlay an image onto a gif, for a certain number of fra

Posted: 2013-09-12T14:39:03-07:00
by xereeto
I take it the same command could be used in a Unix environment, switching the "^"s for "\"s?

Re: Overlay an image onto a gif, for a certain number of fra

Posted: 2013-09-12T14:56:19-07:00
by fmw42
In unix, you also have to escape the parens

convert \
animation.gif[0-11] -coalesce null: overlay1.png -layers composite \
\( animation.gif[1-23] -coalesce null: overlay2.png -layers composite \) \
\( animation.gif[24-35] -coalesce null: overlay3.png -layers composite \) \
-layers optimize o.gif