Saving animated gif to stream

Bug fix when using the file parameter to save an animated gif. Currently not all frames of the gif are saved.