Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in images2gif.py with GlobalPalette

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?

like image 439
matthewlent Avatar asked Oct 03 '13 02:10

matthewlent


3 Answers

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])
like image 180
chappy Avatar answered Oct 23 '22 15:10

chappy


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)

like image 26
Ben G Avatar answered Oct 23 '22 15:10

Ben G


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.

like image 43
MatthieuW Avatar answered Oct 23 '22 16:10

MatthieuW