diff options
| author | Sébastien Theys <seb@odoo.com> | 2019-04-26 10:55:21 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2019-04-29 13:45:03 +0000 |
| commit | d870877967b5debc11d9364ba1572e7aa6956c28 (patch) | |
| tree | 59d3ba22c19dc6d40c8b266f012864bd952621f6 /addons/web/models | |
| parent | b230114fcf41403cbb5fe353f1f94298c958cccc (diff) | |
[IMP] tools,base,web,website_*: keep image ratio on resize
* = website_partner, website_profile, website_sale, website_slides
Before
======
Since commit: 2e3848b394748bf23eff0db0d6d92b9e8c9bf875
The images that are resized have additional borders if the target ratio is
different than the image ratio. Those borders are transparent if the image
format supports it, and are white otherwise.
With that current solution, if the background where the image is displayed is
another color than white, it is looking really bad.
Moreover, most images are stored resized like this, so it is not even possible
to decide if it should have borders or not depending on the context, the
original image and ratio is forever lost.
It is also inconsistent because if the image is already smaller than the target
size then it doesn't include borders. In that case it keeps the original ratio
instead of the target ratio. So it isn't even guaranteed that the target
ratio is going to be respected.
After
=====
This commit will solve all of those problems by always keeping the ratio of the
original image.
This implies the views should be taking care of adding borders when necessary.
task-1958000
PR: #31811
Diffstat (limited to 'addons/web/models')
| -rw-r--r-- | addons/web/models/ir_qweb.py | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/addons/web/models/ir_qweb.py b/addons/web/models/ir_qweb.py index d1d792e8f54..e8a966647e3 100644 --- a/addons/web/models/ir_qweb.py +++ b/addons/web/models/ir_qweb.py @@ -45,7 +45,6 @@ class Image(models.AbstractModel): sha = hashlib.sha1(str(getattr(record, '__last_update')).encode('utf-8')).hexdigest()[0:7] max_size = '' if max_size is None else '/%s' % max_size - avoid_if_small = '&avoid_if_small=true' if options.get('avoid_if_small') else '' if options.get('filename-field') and getattr(record, options['filename-field'], None): filename = record[options['filename-field']] @@ -54,7 +53,7 @@ class Image(models.AbstractModel): else: filename = record.display_name - src = '/web/image/%s/%s/%s%s/%s?unique=%s%s' % (record._name, record.id, options.get('preview_image', field_name), max_size, url_quote(filename), sha, avoid_if_small) + src = '/web/image/%s/%s/%s%s/%s?unique=%s' % (record._name, record.id, options.get('preview_image', field_name), max_size, url_quote(filename), sha) if options.get('alt-field') and getattr(record, options['alt-field'], None): alt = escape(record[options['alt-field']]) |
