From a6cd0742bc0e2a9258bb99facbc6cfbc1a7dadf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Thu, 7 Aug 2008 16:56:14 +0000 Subject: [PATCH] use subprocess module to invoke convert. This requires python2.4 git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22943 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/Image.py | 46 +++++++++++++--------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/product/ERP5/Document/Image.py b/product/ERP5/Document/Image.py index 6d6ab0a642..74e2079ce0 100644 --- a/product/ERP5/Document/Image.py +++ b/product/ERP5/Document/Image.py @@ -33,6 +33,7 @@ import os import string import sys import time +import subprocess from cStringIO import StringIO from AccessControl import ClassSecurityInfo @@ -357,38 +358,27 @@ class Image(File, OFSImage): resolution=None, frame=None): """Resize and resample photo.""" newimg = StringIO() - - # Prepare the format prefix - if format: - format = '%s:' % format + + 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: - format = '' + parameter_list.append('-') - # Prepare the frame suffix - if frame is not None: - frame = '[%s]' % frame + if format: + parameter_list.append('%s:-' % format) 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') + parameter_list.append('-') - 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) + 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): -- 2.30.9