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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
xereeto
Posts: 2
Joined: 2013-09-11T15:08:42-07:00
Authentication code: 6789

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

Post 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!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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
snibgo's IM pages: im.snibgo.com
xereeto
Posts: 2
Joined: 2013-09-11T15:08:42-07:00
Authentication code: 6789

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

Post by xereeto »

I take it the same command could be used in a Unix environment, switching the "^"s for "\"s?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
Post Reply