diff options
| author | Yannick Tivisse <yti@odoo.com> | 2017-09-04 18:16:22 +0200 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2017-09-05 15:52:15 +0200 |
| commit | 2e3848b394748bf23eff0db0d6d92b9e8c9bf875 (patch) | |
| tree | 4bafd9f5fa26d8a4f1ecc946605c321c177c30b5 /addons/web | |
| parent | 6801baa662a01d2e1990094735b22dc512930b2a (diff) | |
[IMP] web: Add the possibility to crop an image in web/image controller
Purpose
=======
Could be useful if you want to load a preview of an image as a thumbnail
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/controllers/main.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index d013a9f9f8b..94e88af0900 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -31,7 +31,7 @@ import odoo import odoo.modules.registry from odoo.api import call_kw, Environment from odoo.modules import get_resource_path -from odoo.tools import topological_sort, html_escape, pycompat +from odoo.tools import crop_image, topological_sort, html_escape, pycompat from odoo.tools.translate import _ from odoo.tools.misc import str2bool, xlwt from odoo.tools.safe_eval import safe_eval @@ -1004,7 +1004,7 @@ class Binary(http.Controller): '/web/image/<int:id>-<string:unique>/<string:filename>', '/web/image/<int:id>-<string:unique>/<int:width>x<int:height>', '/web/image/<int:id>-<string:unique>/<int:width>x<int:height>/<string:filename>'], type='http', auth="public") - def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas', filename_field='datas_fname', unique=None, filename=None, mimetype=None, download=None, width=0, height=0): + def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas', filename_field='datas_fname', unique=None, filename=None, mimetype=None, download=None, width=0, height=0, crop=False): status, headers, content = binary_content(xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename, filename_field=filename_field, download=download, mimetype=mimetype, default_mimetype='image/png') if status == 304: return werkzeug.wrappers.Response(status=304, headers=headers) @@ -1015,7 +1015,11 @@ class Binary(http.Controller): height = int(height or 0) width = int(width or 0) - if content and (width or height): + + if crop and (width or height): + content = crop_image(content, type='center', size=(width, height), ratio=(1, 1)) + + elif content and (width or height): # resize maximum 500*500 if width > 500: width = 500 |
