[Erp5-report] r22943 - /erp5/trunk/products/ERP5/Document/Image.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Aug 7 18:56:15 CEST 2008


Author: jerome
Date: Thu Aug  7 18:56:14 2008
New Revision: 22943

URL: http://svn.erp5.org?rev=22943&view=rev
Log:
use subprocess module to invoke convert. This requires python2.4

Modified:
    erp5/trunk/products/ERP5/Document/Image.py

Modified: erp5/trunk/products/ERP5/Document/Image.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Image.py?rev=22943&r1=22942&r2=22943&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Image.py (original)
+++ erp5/trunk/products/ERP5/Document/Image.py Thu Aug  7 18:56:14 2008
@@ -33,6 +33,7 @@
 import string
 import sys
 import time
+import subprocess
 from cStringIO import StringIO
 
 from AccessControl import ClassSecurityInfo
@@ -357,38 +358,27 @@
                     resolution=None, frame=None):
       """Resize and resample photo."""
       newimg = StringIO()
-
-      # Prepare the format prefix
+      
+      parameter_list = ['convert']
+      if resolution:
+        parameter_list.extend(['-density', '%sx%s' % (resolution, resolution)])
+      parameter_list.extend(['-quality', str(quality)])
+      parameter_list.extend(['-geometry', '%sx%s' % (width, height)])
+      if frame:
+        parameter_list.append('-[%s]' % frame)
+      else:
+        parameter_list.append('-')
+
       if format:
-        format = '%s:' % format
+        parameter_list.append('%s:-' % format)
       else:
-        format = ''
-
-      # Prepare the frame suffix
-      if frame is not None:
-        frame = '[%s]' % frame
-      else:
-        frame = ''
-
-      if sys.platform == 'win32':
-          # XXX - Does win32 support pipe ?
-          from win32pipe import popen2
-          if resolution is None:
-            imgin, imgout = popen2('convert -quality %s -geometry %sx%s -%s %s-'
-                            % (quality, width, height, frame, format), 'b')
-          else:
-            imgin, imgout = popen2('convert -density %sx%s -quality %s -geometry %sx%s -%s %s-'
-                            % (resolution, resolution, quality, width, height, frame, format), 'b')
-
-      else:
-          from popen2 import popen2
-          if resolution is None:
-            cmd = 'convert -quality %s -geometry %sx%s -%s %s-' % (
-                    quality, width, height, frame, format)
-          else:
-            cmd = 'convert -density %sx%s -quality %s -geometry %sx%s -%s %s-' % (
-                    resolution, resolution, quality, width, height, frame, format)
-          imgout, imgin = popen2(cmd)
+        parameter_list.append('-')
+
+      process = subprocess.Popen(parameter_list,
+                                 stdin=subprocess.PIPE,
+                                 stdout=subprocess.PIPE,
+                                 close_fds=True)
+      imgin, imgout = process.stdin, process.stdout
 
       def writeData(stream, data):
         if isinstance(data, str):




More information about the Erp5-report mailing list