Jade O'Connor's solution works but as said it's an ugly solution.
Because each time you visit the page the image is downloaded from the server. This leads to bandwith problems for large images. This also increases the page loading time, hence it's bad for slow connections.
Is there a better solution?
I figured out something like this:
I regenerated the animated gif in loop "forever" mode. In my gif, there were 20 frames and each one is shown for 150 ms. So that one step of the loop lasts for 3 seconds. I also created a jpeg version of the last frame of the animation.
When the page loads I used window.setTimeout() method for replacing the gif with the jpeg after 3 seconds. Because, I wanted the final frame stand still when the first step of the loop is finished. But there were timing problems. When the last frame is shown the animation restarts before I could replace the gif by the jpeg. Is there a way to detect if the animation is finished or restarted?