Appending an animated gif to a static image

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
bertez
Posts: 2
Joined: 2018-04-05T06:10:34-07:00
Authentication code: 1152

Appending an animated gif to a static image

Post by bertez »

Hi, I have an static jpg image and I want to append an animated gif below the jpg to generate a animated image combining both, this is what I want to achieve:

Image

I'm using this (naive) command:

Code: Select all

convert background.jpg animated.gif -append -loop 0 result.gif
The problem is the result shows the gif splitted frame by frame, like this:

Image

Any help would be appreciated.

Thanks in advance
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Appending an animated gif to a static image

Post by fmw42 »

try

Code: Select all

convert background.jpg null: \( animated.gif -coalesce \) -compose over -layers composite -layers optimize result.gif
see https://www.imagemagick.org/Usage/anim_ ... ite_single
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Appending an animated gif to a static image

Post by GeeMack »

bertez wrote: 2018-04-05T06:26:04-07:00Hi, I have an static jpg image and I want to append an animated gif below the jpg to generate a animated image combining both,...
Here's a command that should give you nearly the result you've described...

Code: Select all

convert background.jpg -alpha set -background none \( animated.gif -coalesce \) \
   -set page "%[fx:u.w]x%[fx:u.h+v.h]+%[fx:t?(u.w-v.w)/2:0]+%[fx:t?u.h:0]" -coalesce \
   null: -insert 1 -layers composite -loop 0 result.gif
First it reads in your background JPG, then reads in your animated GIF and turn it into full frames.

Then it builds a canvas around each image the width of the background image, and the total height of the background plus a GIF frame. It also sets the geometry to locate the animated frames centered at the bottom of the background image.

Next it uses a "null:" separator and "-layers composite" to essentially append each animated frame to the bottom of a copy of the background image.

Then add your "-loop 0", delays, optimizing, etc., and output the finished GIF.

This is in *nix syntax. To use a command like this in Windows, change all the continued-line backslashes "\" into carets "^", and remove the backslash escapes "\( \)" from the parentheses "( )". In a Windows BAT script you'll need to change the single percent signs "%" to doubles "%%".
bertez
Posts: 2
Joined: 2018-04-05T06:10:34-07:00
Authentication code: 1152

Re: Appending an animated gif to a static image

Post by bertez »

Thank you very much, both solutions worked fine!

Problem solved!
Post Reply