From d59417c879c60c6c124e1a9c638718d22e66880b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 8 Nov 2012 11:24:23 +0100 Subject: [PATCH] [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 --- addons/web/controllers/main.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index ad8d91ed1dd..7f53482619c 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -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))