Add image to end of gif

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
rabelcher22
Posts: 4
Joined: 2015-05-26T11:37:53-07:00
Authentication code: 6789

Add image to end of gif

Post by rabelcher22 »

I need help or a nudge in the right direction. I am trying to take a gif (animated.gif) and add an image (extra.png) to the end of that gif. What command am I looking for? Any help would be great.
rabelcher22
Posts: 4
Joined: 2015-05-26T11:37:53-07:00
Authentication code: 6789

Re: Add image to end of gif

Post by rabelcher22 »

I think I figured it out after having an epiphany.

I just used to convert command.

convert -delay 50 @fileList.txt animated.gif where fileList contains the lines

animated.gif
extra.png

Is this the most efficient way to do this?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Add image to end of gif

Post by snibgo »

You can do it more directly:

Code: Select all

convert -delay 50 animated.gif extra.png animated.gif
This reads in all the frames in animated.gif. Then it reads the image in extra.png. Then it writes all the images to animated.gif.

When testing, you should write to a different filename, eg animated2.gif.
snibgo's IM pages: im.snibgo.com
rabelcher22
Posts: 4
Joined: 2015-05-26T11:37:53-07:00
Authentication code: 6789

Re: Add image to end of gif

Post by rabelcher22 »

Thank you for the testing advice. Do you know if this method I came to is the best way to do the action?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Add image to end of gif

Post by snibgo »

In ImageMagick, it's the only way (as far as I know).

You might need an extra step. Many animated GIFs are optimized, which means each frame stores only the difference from the previous frame. So it is generally better to do this:

Code: Select all

convert -delay 50 animated.gif -layers coalesce extra.png animated.gif
"-layers coalesce" makes each image the full picture, rather than just the pixels that have changed. You might want to optimise the result:

Code: Select all

convert -delay 50 animated.gif -layers coalesce extra.png -layers optimize animated.gif
snibgo's IM pages: im.snibgo.com
rabelcher22
Posts: 4
Joined: 2015-05-26T11:37:53-07:00
Authentication code: 6789

Re: Add image to end of gif

Post by rabelcher22 »

Thank you for all of the help!
Post Reply