[Scipy-svn] r2744 - trunk/Lib/misc

scipy-svn@scip... scipy-svn@scip...
Thu Feb 22 03:41:10 CST 2007


Author: stefan
Date: 2007-02-22 03:41:02 -0600 (Thu, 22 Feb 2007)
New Revision: 2744

Modified:
   trunk/Lib/misc/pilutil.py
Log:
Clean up misc.pilutil.imshow.


Modified: trunk/Lib/misc/pilutil.py
===================================================================
--- trunk/Lib/misc/pilutil.py	2007-02-22 08:46:08 UTC (rev 2743)
+++ trunk/Lib/misc/pilutil.py	2007-02-22 09:41:02 UTC (rev 2744)
@@ -2,6 +2,7 @@
 
 import types
 import numpy
+import tempfile
 
 from numpy import amin, amax, ravel, asarray, cast, arange, \
      ones, newaxis, transpose, mgrid, iscomplexobj, sum, zeros, uint8
@@ -226,19 +227,22 @@
     """Simple showing of an image through an external viewer.
     """
     im = toimage(arr)
-    if (len(arr.shape) == 3) and (arr.shape[2] == 4):
-        try:
-            import os
-            im.save('/tmp/scipy_imshow.png')
-            if os.system("(xv /tmp/scipy_imshow.png; rm -f /tmp/scipy_imshow.png)&"):
-                raise RuntimeError
-            return
-        except:
-            print "Warning: Alpha channel may not be handled correctly."
+    fnum,fname = tempfile.mkstemp('.png')
+    try:
+        im.save(fname)
+    except:
+        raise RuntimeError("Error saving temporary image data.")
 
-    im.show()
-    return
+    import os
+    os.close(fnum)
 
+    cmd = os.environ.get('SCIPY_PIL_IMAGE_VIEWER','see')
+    status = os.system("%s %s" % (cmd,fname))
+
+    os.unlink(fname)
+    if status != 0:
+        raise RuntimeError('Could not execute image viewer.')
+
 def imresize(arr,size):
     """Resize an image.
 



More information about the Scipy-svn mailing list