diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 6af25b7eaa0..fd24d253c21 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1031,7 +1031,7 @@ class Binary(http.Controller): '/web/image/-/x/'], 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, crop=False, access_token=None): + download=None, width=0, height=0, crop=False, access_token=None, avoid_if_small=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, @@ -1055,7 +1055,7 @@ class Binary(http.Controller): width = 500 if height > 500: height = 500 - content = odoo.tools.image_resize_image(base64_source=content, size=(width or None, height or None), encoding='base64', filetype='PNG') + content = odoo.tools.image_resize_image(base64_source=content, size=(width or None, height or None), encoding='base64', filetype='PNG', avoid_if_small=avoid_if_small) # resize force png as filetype headers = self.force_contenttype(headers, contenttype='image/png') diff --git a/addons/web/models/ir_qweb.py b/addons/web/models/ir_qweb.py index 5c94da64d53..a7376e04b5d 100644 --- a/addons/web/models/ir_qweb.py +++ b/addons/web/models/ir_qweb.py @@ -42,7 +42,8 @@ class Image(models.AbstractModel): sha = hashlib.sha1(getattr(record, '__last_update').encode('utf-8')).hexdigest()[0:7] max_size = '' if max_size is None else '/%s' % max_size - src = '/web/image/%s/%s/%s%s?unique=%s' % (record._name, record.id, field_name, max_size, sha) + avoid_if_small = '&avoid_if_small=true' if options.get('avoid_if_small') else '' + src = '/web/image/%s/%s/%s%s?unique=%s%s' % (record._name, record.id, field_name, max_size, sha, avoid_if_small) alt = None if options.get('alt-field') and getattr(record, options['alt-field'], None):