11

I've created a short animation using Python, Pillow (a fork of PIL), and cairo. The current animation is 334 frames. I can save a single frame using the following code...

frame_images[0].save('test_frame.gif')

and I will get a 34 kb file. I have been creating gifs using the save_all option in pillow...

frame_images[0].save('test.gif', save_all=True, append_images=frame_images[1:], loop=0)

And the result does not work as expected. The output is 22.8 MB, more than twice the size of a single frame times 334, and the quality is substantially degraded. There are artifacts all over the image, several frames have remnants from previous frames, and the color of the items often appear incorrectly.

Does anybody have any suggestions for fixing this issue? Should I just Pillow to save still frames and then a different library to create a gif?

neelshiv
  • 6,125
  • 6
  • 21
  • 35
  • 1
    This might be relevant: [Saving an animated GIF in Pillow](http://stackoverflow.com/questions/24688802/saving-an-animated-gif-in-pillow). Sorry I can't offer more help. Although I've used Pillow a bit I've never tried making GIF anims with it, and the last time I made an anim with Cairo I just saved individual frames and used ImageMagick or gifsicle to build the anim. – PM 2Ring Oct 14 '16 at 13:01
  • Thanks! I've actually read that. That script has been updated to use the approach that I am using. It is actually a feature in the newest version of Pillow. Unfortunately, it might still be a bit rough around the edges (or maybe I'm using it incorrectly). – neelshiv Oct 14 '16 at 13:14
  • 1
    Are your images paletted or are you relying on Pillow to do the conversion? – Mark Ransom Oct 14 '16 at 15:24
  • I'm not totally sure, but it sounds like I might be relying on pillow. The image files are created by passing a 500x500x4 numpy array, `pic`, into the following function: `Image.fromarray(pic).convert('RGB')`. The array contains values between 0 and 255 for each of the 4 layers in the third dimension (R,G,B,A?) – neelshiv Oct 14 '16 at 17:31
  • 1
    If the image mode is `'RGB'` then Pillow does the conversion when it saves the file. That might be the source of your errors. For best results you need to convert them all to mode `'P'` using the same palette, with no transparency. – Mark Ransom Oct 16 '16 at 02:27
  • I create each image using `Image.fromarray(pic).convert('P')`, but that didn't work. I still got a fairly large file with several colors that changed throughout the image. I suspect it is possible that each image does not have the same palette. – neelshiv Oct 18 '16 at 19:54
  • 1
    Anybody figured this out? I also have problem with the quality. – Anna Jul 12 '17 at 03:38

0 Answers0