Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Merge gif and image
#1
A newbie here with hopefully a quick easy question. I don't know what I am doing, but I try.

I have two files, animated.gif and image.png and I want to make a gif that combines the two. The image.png is larger than the gif and I want the gif in the middle. I tried copy paste and I only got one panel of the animated gif. I tried other things and then the image flashed with the gif.

Is it possible to put a gif in the middle of a static image? If so how?

thanks for the help
Lee
Reply
#2
Maybe this link can help you : https://www.gimp-forum.net/Thread-Combin...hlight=gif
Reply
#3
(01-13-2023, 12:50 AM)Lee Wrote: I have two files, animated.gif and image.png and I want to make a gif that combines the two. The image.png is larger than the gif and I want the gif in the middle. I tried copy paste and I only got one panel of the animated gif. I tried other things and then the image flashed with the gif.

Is it possible to put a gif in the middle of a static image? If so how?

Unless you do all by hand one-layer at a time you need a script to merge the background layer with each layer of the animation.

Open the background image first, then open as layers the animation file. That will plant the animation in the center of the background.

Some caveats to consider.

The animation first.
If it is optimized, un-optimize it. Filters -> Animation -> Unoptimize (edit - missed that typo )
For a gif change the color mode to RGB Image -> Mode -> RGB 
If you want to do any editing, now is the time to do it.
Save this as a new file something.xcf (preferred) or export as a gif something.gif 

Open the background layer. If it is indexed color, change that to RGB Not needed for a png.
Open as layers the animation and that puts it above the background layer.

To add the background to each layer use the attached script sg-combine-bg.scm (no need to resize the animation with this script). Make sure the background (bottom) layer is active and run the script. The background layer is now not needed and you can delete it.

Always Save your work as a Gimp .xcf in case you need to go back for more editing. 
Export as a file.gif 

Any number of YT videos on the subject. I am not proud, here is another: https://youtu.be/FjnAmE-nd7U  4.5 minutes duration.





The attachment contains 2 scripts the sg-combine-bg.scm and a utility for removing a plain color background from the original animation (if needed)  Unzip and put in C:\Users\"yourname"\AppData\Roaming\GIMP\2.10\scripts


Attached Files
.zip   combine-bg.zip (Size: 1.9 KB / Downloads: 121)
Reply
#4
It took a while to figure out and some experimenting but I got just what I wanted. I paused the video a lot and got lost when he used a script. But then I realized you attached the script for me. Early on I had most of it but there was a pause/flash when the gif restarted. Watched the video again and got it.
Thanks a lot
Lee
Reply
#5
(01-13-2023, 09:33 AM)rich2005 Wrote:
Unless you do all by hand one-layer at a time you need a script to merge the background layer with each layer of the animation.


A funny thing happened to me on the way to the office today.  Smile

I was going through the motions of this thread,  as I often do, just trying to expand my horizons

And opened a 800x600 png image, and then opened as layers a 480x368  20 frame gif, and then went to Filters>Animation and selected "unoptimize" from the menu.....and Gimp added the base .png image to each and every of the 20 animation layer---no script required  All I had to do was merge the original "background" layer of the original gif down into the base .png below it in the stack......and I was good to go.  the resulting file exported equally well in either "replace" or "combine" mode as an animated gif

The reason I even mention this, is because it was a lot easier than fiddling with a script.  Am I missing something?



This got me to thinking. I opened another copy of the original png file, and then opened as layers the  20 frame gif, again merging the gif background layer into the png below it in the stack, and then exported it in "combine" mode as an animated gif

no other processing.....and it seems to run equally well. But again, am I missing something? the solution  seems on the surface almost too simple. 

One caveat seems to be that the gif itself must not be optimized to begin with.

Do you see any down side to what I'm doing with this?

thanks in advance


Reply
#6
Clever (t)rickk.

However, what you get isn't the background BG added to each layer L1 .. Ln: BG+L1, BG+L2, .. BG+Ln. What you get is the background added to a progressive accumulation of layers: BG+L1, BG+L1+L2, .. , BG+L1+L2+..+Ln. This can be fine if you just use the result as an animation (but then if you don't do this you already have the optimized result...).

In addition, it seems to lose the anti-aliasing, even though the layers are not color-indexed. Not a problem if you export to GIF (you will lose it anyway) but nasty if you export to animated WebP.
Reply
#7
You're right, of course.

Another thing that I just noticed is the markedly different behavior in the way the "unoptimize" function integrates the static underlying image into the above layers, depending upon if the gif opened as layers is initially in "replace" vs "combine" mode.

"Combine" being what I originally worked with.


Reply


Forum Jump: