Commit a6cd0742 authored by Jérome Perrin's avatar Jérome Perrin

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
parent c4770846
......@@ -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):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment