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 ...@@ -33,6 +33,7 @@ import os
import string import string
import sys import sys
import time import time
import subprocess
from cStringIO import StringIO from cStringIO import StringIO
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
...@@ -358,37 +359,26 @@ class Image(File, OFSImage): ...@@ -358,37 +359,26 @@ class Image(File, OFSImage):
"""Resize and resample photo.""" """Resize and resample photo."""
newimg = StringIO() newimg = StringIO()
# Prepare the format prefix parameter_list = ['convert']
if format: if resolution:
format = '%s:' % format 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: else:
format = '' parameter_list.append('-')
# Prepare the frame suffix if format:
if frame is not None: parameter_list.append('%s:-' % format)
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: else:
imgin, imgout = popen2('convert -density %sx%s -quality %s -geometry %sx%s -%s %s-' parameter_list.append('-')
% (resolution, resolution, quality, width, height, frame, format), 'b')
else: process = subprocess.Popen(parameter_list,
from popen2 import popen2 stdin=subprocess.PIPE,
if resolution is None: stdout=subprocess.PIPE,
cmd = 'convert -quality %s -geometry %sx%s -%s %s-' % ( close_fds=True)
quality, width, height, frame, format) imgin, imgout = process.stdin, process.stdout
else:
cmd = 'convert -density %sx%s -quality %s -geometry %sx%s -%s %s-' % (
resolution, resolution, quality, width, height, frame, format)
imgout, imgin = popen2(cmd)
def writeData(stream, data): def writeData(stream, data):
if isinstance(data, str): 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