[GRASS-SVN] r61417 - grass/trunk/lib/python/imaging

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jul 26 18:53:13 PDT 2014


Author: annakrat
Date: 2014-07-26 18:53:12 -0700 (Sat, 26 Jul 2014)
New Revision: 61417

Modified:
   grass/trunk/lib/python/imaging/images2gif.py
Log:
wxGUI/animation: fix GIF export for Pillow, #2177

Modified: grass/trunk/lib/python/imaging/images2gif.py
===================================================================
--- grass/trunk/lib/python/imaging/images2gif.py	2014-07-26 23:37:46 UTC (rev 61416)
+++ grass/trunk/lib/python/imaging/images2gif.py	2014-07-27 01:53:12 UTC (rev 61417)
@@ -70,6 +70,11 @@
 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 @@
         """ 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 ) )
         



More information about the grass-commit mailing list