I'm working on a simple script to download a series of radar images, add overlays to them, then turn them into an animated gif. I'm using Pillow and images2gif from the visvis package. I asked a question earlier about stacking the transparent gif files. I managed to get this working, but images2gif is throwing an error. Here is the relevant code from my project:
from PIL import Image
from visvis.vvmovie.images2gif import writeGif as gif
background = Image.open("%IMAGEDIR%\Background.png")
overlay = Image.open("%IMAGEDIR%\Overlay.png")
frames = []
for i in range (10, 0, -1):
imagenum = ("%02d" % i)
radar = Image.open("%IMAGEDIR%\" + imagenum + ".gif")
radar = radar.convert("RGBA")
background.paste(radar, (0,0), radar)
background.paste(overlay, (0,0), overlay)
background.convert("RGB").convert("P", palette = Image.ADAPTIVE)
frames.append(background)
print ("Writing image!")
gif("%IMAGEDIR%\animation.gif", frames)
print ("Done!")
However, this throws an error from images2gif:
Traceback (most recent call last):
File "%IMAGEDIR%\images.py", line 62, in <module>
gif("%IMAGEDIR%\animation.gif", frames)
File "C:\Python34\lib\site-packages\visvis\vvmovie\images2gif.py", line 578, in writeGif
gifWriter.writeGifToFile(fp, images, duration, loops, xy, dispose)
File "C:\Python34\lib\site-packages\visvis\vvmovie\images2gif.py", line 418, in writeGifToFile
raise RuntimeError('Cannot get palette. '
RuntimeError: Cannot get palette. Maybe you should try imageio instead.
Going to the relevant lines in images2gif, I find this:
# Obtain palette for all images and count each occurance
palettes, occur = [], []
for im in images:
palette = getheader(im)[1]
if not palette:
palette = PIL.ImagePalette.ImageColor
if isinstance(palette, type(os)):
# Older or newer? version of Pil(low)
data = PIL.ImagePalette.ImagePalette().getdata()
palette = data[0].encode('utf-8') + data[1]
# Arg this does not work. Go use imageio
raise RuntimeError('Cannot get palette. '
'Maybe you should try imageio instead.')
palettes.append(palette)
for palette in palettes:
occur.append(palettes.count(palette))
I've never used imageio, and I'm already using PIL which is supposed to work with images2gif. Ideally, I don't want to have to save the images to the disk -- they are small files, but I'd like to get this working however I can.
Thanks a lot for any help!
NOTE: I'm using Python 3.4 on Windows 10 with numpy 1.9.2 and visvis 1.9.2 to test it, but this script is going to be used on PythonAnywere.
试试这个版本,可以和我一起使用(带枕头2.9): https : //github.com/rec/echomesh/blob/master/code/python/external/images2gif.py
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.