[IMP] web controllers: add resize option on /web/binary/?image. The max size of resizing is 500*500.

bzr revid: chm@openerp.com-20121108102423-oh5633zqlj4g762o
This commit is contained in:
Christophe Matthieu 2012-11-08 11:24:23 +01:00
parent c045cdd502
commit d59417c879
1 changed files with 15 additions and 2 deletions

View File

@ -1516,11 +1516,24 @@ class Binary(openerpweb.Controller):
try:
if not id:
res = Model.default_get([field], context).get(field)
image_data = base64.b64decode(res)
image_base64 = res
else:
res = Model.read([id], [last_update, field], context)[0]
retag = hashlib.md5(res.get(last_update)).hexdigest()
image_data = base64.b64decode(res.get(field))
image_base64 = res.get(field)
if kw.get('resize'):
resize = kw.get('resize').split(',');
if len(resize) == 2 and int(resize[0]) and int(resize[1]):
width = int(resize[0])
height = int(resize[1])
# resize maximum 500*500
if width > 500: width = 500
if height > 500: height = 500
image_base64 = openerp.tools.image_resize_image(base64_source=image_base64, size=(width, height), encoding='base64', filetype='PNG')
image_data = base64.b64decode(image_base64)
except (TypeError, xmlrpclib.Fault):
image_data = self.placeholder(req)
headers.append(('ETag', retag))