Fix handling of multi-image gifs and add test