16

Getting an error when trying to convert sequence of jpgs to gifs. Can't seem to figure out how to add a palette, or if that's the actual problem. Was able to get gifs to load using the numpy arrays in the images2gif.py main.

import PIL
from PIL import Image
import StringIO
import images2gif

images = []
for frame in animation1.frames:
    img_data = s3manager.get_file_as_string(frame.s3_filename)
    image = Image.open(StringIO.StringIO(img_data))
    images.append(image)

images2gif.writeGif('lala3.gif', images, duration=0.5, dither=0)  

With this I get the following error:

"images2gif.py", line 436, in writeGifToFile
  fp.write(globalPalette)
TypeError: must be string or buffer, not None

Not sure how to specify a palette for these jpgs. documentation unclear to me, and not even sure if that's the issue. help?

matthewlent
  • 549
  • 4
  • 18
  • Have the same problem. It worked for me before I had to reinstall Pillow because it was missing some of the dependencies needed to work with PNG files. – Petr Peller Nov 06 '13 at 16:57

4 Answers4

26

In images2gif.py change line 200:

for im in images:
    palettes.append( getheader(im)[1] )

to

for im in images:
    palettes.append(im.palette.getdata()[1])
chappy
  • 1,077
  • 1
  • 10
  • 14
2

images2gif author seems to be willing to drop support for pillow. See this thread :

https://code.google.com/p/visvis/issues/detail?id=81

From this thread too, i found a fixed version of that script, which works with me (with pillow 2.4). It is available here : https://github.com/rec/echomesh/blob/master/code/python/external/images2gif.py and produces good quality gif with any kind of PNG (P mode too)

Ben G
  • 3,965
  • 3
  • 30
  • 34
1

images2gif.py uses getheader function from PIL.GifImagePlugin to get the palettes.

For some reason, it doesn't work with image you read. Maybe the script doesn't really work if source images are not 'P' mode.

MatthieuW
  • 2,292
  • 15
  • 25
0

I installed PIL after Pillow and it started to work. Seems like both libraries are needed for some reason. Here is how to reinstall both:

pip uninstall PIL
pip uninstall Pillow
pip install Pillow
pip install PIL
Petr Peller
  • 8,581
  • 10
  • 49
  • 66
  • That's kind of hard to believe. PIL and Pillow both install to the same name, PIL - so how is it possible for an application program to use symbols from both libraries? – Tom Swirly Feb 24 '14 at 21:47
  • And if this is true, then it's a serious bug in Pillow and need to be tracked down and reported! Pillow is supposed to be a fork of the inactive PIL project - if it only works if you then re-install the (old, broken) PIL, then something's wrong. – Tom Swirly Feb 24 '14 at 22:10