Commit 619c59a8 authored by Bartek Górny's avatar Bartek Górny

fixed resize function because it did not work (and needlesly used filesystem)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12372 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent aa3e0590
...@@ -29,6 +29,12 @@ ...@@ -29,6 +29,12 @@
# #
############################################################################## ##############################################################################
import os
import string
import sys
import time
from cStringIO import StringIO
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Acquisition import aq_base from Acquisition import aq_base
...@@ -39,8 +45,6 @@ from Products.ERP5.Document.File import File ...@@ -39,8 +45,6 @@ from Products.ERP5.Document.File import File
from OFS.Image import Image as OFSImage from OFS.Image import Image as OFSImage
from OFS.Image import getImageInfo from OFS.Image import getImageInfo
from OFS.content_types import guess_content_type from OFS.content_types import guess_content_type
import string, time, sys
from cStringIO import StringIO
from zLOG import LOG from zLOG import LOG
...@@ -301,40 +305,30 @@ class Image(File, OFSImage): ...@@ -301,40 +305,30 @@ class Image(File, OFSImage):
def _resize(self, display, width, height, quality=75, format='', resolution=None): def _resize(self, display, width, height, quality=75, format='', resolution=None):
"""Resize and resample photo.""" """Resize and resample photo."""
newimg = StringIO() newimg = StringIO()
os.putenv('TMPDIR', '/tmp') # because if we run zope as root, we have /root/tmp here and convert goes crazy
if sys.platform == 'win32': if sys.platform == 'win32':
from win32pipe import popen2 from win32pipe import popen2
from tempfile import mktemp
newimg_path = mktemp(suffix=format)
if resolution is None: if resolution is None:
imgin, imgout = popen2('convert -quality %s -geometry %sx%s - %s' imgin, imgout = popen2('convert -quality %s -geometry %sx%s - -'
% (quality, width, height, newimg_path), 'b') % (quality, width, height), 'b')
else: else:
imgin, imgout = popen2('convert -density %sx%s -quality %s -geometry %sx%s - %s' imgin, imgout = popen2('convert -density %sx%s -quality %s -geometry %sx%s - -'
% (resolution, resolution, quality, width, height, newimg_path), 'b') % (resolution, resolution, quality, width, height), 'b')
else: else:
from popen2 import popen2 from popen2 import popen2
import tempfile
tempdir = tempfile.tempdir
tempfile.tempdir = '/tmp'
newimg_path = tempfile.mktemp(suffix='.' + format)
tempfile.tempdir = tempdir
if resolution is None: if resolution is None:
imgout, imgin = popen2('convert -quality %s -geometry %sx%s - %s' imgout, imgin = popen2('convert -quality %s -geometry %sx%s - -'
% (quality, width, height, newimg_path)) % (quality, width, height))
else: else:
LOG('Resolution',0,str(resolution)) LOG('Resolution',0,str(resolution))
imgout, imgin = popen2('convert -density %sx%s -quality %s -geometry %sx%s - %s' cmd = 'convert -density %sx%s -quality %s -geometry %sx%s - -' % (resolution, resolution, quality, width, height)
% (resolution, resolution, quality, width, height, newimg_path)) imgout, imgin = popen2(cmd)
imgin.write(str(self.getData())) imgin.write(str(self.getData()))
imgin.close() imgin.close()
imgout.read() newimg.write(imgout.read())
imgout.close()
newimg_file = open(newimg_path, 'r')
newimg.write(newimg_file.read())
newimg_file.close()
newimg.seek(0) newimg.seek(0)
return newimg return newimg
......
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