I've written a program that creates a gif animation using Pillow and images2gif. A short while ago I had everything working perfectly, but decided to switch from 64 bit to 32 bit python as I'd heard there was greater library support. After reinstalling python my program failed to generate gifs properly, which I suspect is due to changing the installed package versions. I have tried using different versions of images2gif, numpy, and Pillow but this has not solved the problem.
A simple script demonstrating the problem is:
from PIL import Image
from images2gif import writeGif
frames = []
frames.append(Image.open('program_data/background_images/Half Court - MF AD.png'))
frames.append(Image.open('program_data/background_images/Half Court - AD.png'))
writeGif('test_output_image.gif', frames, subRectangles=True, duration=0.5, dispose=1)
My initial problem threw the error:
Traceback (most recent call last):
File "C:/Users/Michael/Documents/Python_Scripts/GUI_animator/why_broken.py", line 7, in <module>
writeGif('test_output_image.gif', frames, subRectangles=True, duration=0.5, dispose=1)
File "C:\Python27\lib\site-packages\images2gif\images2gif.py", line 571, in writeGif
images, xy, images_info = gifWriter.handleSubRectangles(images, subRectangles)
File "C:\Python27\lib\site-packages\images2gif\images2gif.py", line 295, in handleSubRectangles
images, xy = self.getSubRectangles(images)
File "C:\Python27\lib\site-packages\images2gif\images2gif.py", line 347, in getSubRectangles
im2 = im[y0:y1,x0:x1]
TypeError: only integer scalar arrays can be converted to a scalar index
Which I believe is due to numpy no longer supporting 1d length 1 arrays for indices, solved by changing lines 340 and 341 in images2gif.py:
x0, x1 = X[0], X[-1]+1
y0, y1 = Y[0], Y[-1]+1
to:
x0, x1 = int(X[0]), int(X[-1]+1)
y0, y1 = int(Y[0]), int(Y[-1]+1)
However I now get the error:
Traceback (most recent call last):
File "C:/Users/Michael/Documents/Python_Scripts/GUI_animator/why_broken.py", line 7, in <module>
writeGif('test_output_image.gif', frames, subRectangles=True, duration=0.5, dispose=1)
File "C:\Python27\lib\site-packages\images2gif\images2gif.py", line 593, in writeGif
gifWriter.writeGifToFile(fp, images, duration, loops, xy, dispose)
File "C:\Python27\lib\site-packages\images2gif\images2gif.py", line 449, in writeGifToFile
fp.write(globalPalette)
TypeError: argument 1 must be string or buffer, not None
I have tried following these instructions (github.com/almarklein/visvis/issues/81 and stackoverflow.com/questions/19149643/error-in-images2gif-py-with-globalpalette) to change line 426 of images2gif.py from:
palettes.append( getheader(im)[1] )
to either of:
palettes.append( getheader(im)[0][-1] )
palettes.append( im.palette.getdata()[1] )
and have also tried (copying this code) to add under the above line:
if not palette[-1]:
palette[-1] = im.palette.tobytes()
All three of these alterations allow the program to create the gif file, but it is a garbled mess (see google drive link).
My versions are:
Python 2.7.13 (windows 32bit)
Pillow 4.0.0
Numpy 1.12.0+mkl
images2gif 1.0.1
My relevant files and copies of the above packages (from my c:/Python27/Lib/site-packages directory) are available on google drive.
As mentioned, the first code block above is a simple example to demonstrate the problem. Once I've got that fixed I'll actually be running animator.py and passing demo_config_file.py as input, which worked fine before changing my installation.
Any ideas why the palette isn't loading correctly, or whether my problem's something completely different?