[GRASS-SVN] r61427 - grass/branches/releasebranch_7_0/lib/python/imaging

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 28 06:35:08 PDT 2014


Author: annakrat
Date: 2014-07-28 06:35:08 -0700 (Mon, 28 Jul 2014)
New Revision: 61427

Modified:
   grass/branches/releasebranch_7_0/lib/python/imaging/images2gif.py
Log:
wxGUI/animation: fix GIF export for Pillow, #2177 (merge from trunk, r61417)

Modified: grass/branches/releasebranch_7_0/lib/python/imaging/images2gif.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/imaging/images2gif.py	2014-07-28 12:25:42 UTC (rev 61426)
+++ grass/branches/releasebranch_7_0/lib/python/imaging/images2gif.py	2014-07-28 13:35:08 UTC (rev 61427)
@@ -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