Paul
Paul

Reputation: 1186

Can you show a static image after some animation loops in a gif?

I have an animated gif that I want to loop n times (animation.gif). After the loop, I want to show a static image (static.gif). The animation will be displayed over the web, so the file size needs to be a small as possible.

I tried implementing it with Imagemagick by adding the static image with a zero delay ...

convert -loop 3 animated.gif -delay 0 static.gif newanim.gif

Although the static image is shown in the end, the problem is that after every iteration static.gif is shown for a split second.

Another thing I tried was to add the animation 3 times and the static image at the end. This works perfectly but the file becomes too large especially if the animation is long, and if it is looped many times. For instance, a 6.1mb animation becomes ~18mb.

convert -loop 1 animated.gif animated.gif animated.gif static.gif newanim.gif

I'm using Python in a linux environment to implement this, so if there are programmatic ways of doing this instead of Imagemagick that would work as well.

EDIT: I failed to mention a constraint: it needs to work without any client side programming (Javascript, CSS, etc). It needs to be a purely gif solution. This constraint makes it different from How to stop an animated gif from looping

Upvotes: 3

Views: 995

Answers (2)

Jurijs Kovzels
Jurijs Kovzels

Reputation: 6220

I'm pretty sure that your problem with resulting gif size is in tools you are using. I've created those samples, one with animation and another with animation repeated 2 times and got the same size for both. Check it yourself:

single loop two loops

I've used ScreenToGif, it is super buggy and only works on Windows but does its job and can open existing gif or list of images for editing.

If you need solution for Linux take a look at FFmpeg, but I didn't used it myself.

Upvotes: 0

PM 2Ring
PM 2Ring

Reputation: 55479

No, you can't. The GIF anim format doesn't provide that ability.

There are various ways to do what you want on a Web page, but you'll need to have a separate file for the static image, and you'll need some code (eg JavaScript, or maybe CSS) to display the static image after the desired number of anim loops.

Upvotes: 5

Related Questions