Explorar el Código

wxGUI/animation: fix GIF export for Pillow, https://trac.osgeo.org/grass/ticket/2177

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61417 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová hace 10 años
padre
commit
17112e418a
Se han modificado 1 ficheros con 15 adiciones y 1 borrados
  1. 15 1
      lib/python/imaging/images2gif.py

+ 15 - 1
lib/python/imaging/images2gif.py

@@ -70,6 +70,11 @@ import os, time
 try:
     import PIL
     from PIL import Image
+    pillow = True
+    try:
+        from PIL import PILLOW_VERSION  # test if user has Pillow or PIL
+    except ImportError:
+        pillow = False
     from PIL.GifImagePlugin import getheader, getdata
 except ImportError:
     PIL = None
@@ -404,13 +409,22 @@ class GifWriter:
         """ writeGifToFile(fp, images, durations, loops, xys, disposes)
         
         Given a set of images writes the bytes to the specified stream.
+        Requires different handling of palette for PIL and Pillow:
+        based on https://github.com/rec/echomesh/blob/master/
+        code/python/external/images2gif.py
         
         """
         
         # Obtain palette for all images and count each occurance
         palettes, occur = [], []
         for im in images:
-            palettes.append( getheader(im)[1] )
+            if not pillow:
+                palette = getheader(im)[1]
+            else:
+                palette = getheader(im)[0][-1]
+                if not palette:
+                    palette = im.palette.tobytes()
+            palettes.append(palette)
         for palette in palettes:
             occur.append( palettes.count( palette ) )