There are too many image sizes. Since they are stored resized this takes time to generate when saving a new image, it's more rows on the attachment table, more files on the disk, ... 64px is close enough to 128px that it can be removed without a big impact on download size. It will even reduce download and number of requests when both images are displayed because now only one has to be downloaded and then benefit from cache. The difference between the two is typically around 1.5kB which is negligible these days, especially when the request overhead is around 0.5kB already, not even taking into account other factors such as latency. If a 64px image must absolutely be returned, it is still possible to pass the size parameters to the image route. But the current guideline is to handle resizing in the views when necessary. Views ===== - remove width and height attributes when existing CSS rules are overriding them (eg. `.oe_kanban_avatar` in the right context) - add CSS rules instead of width and height attributes when possible - use `object-fit: cover;` where width and height are forced to avoid distortion of non-square images - for products, use `object-fit: contain;` instead, keep ratio but without crop - add new CSS rules where the expected size was max 64px*64px before due to the image size itself - remove `img-fluid` where using size classes to avoid conflicting rules task-2060865 closes odoo/odoo#36147 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
60 lines
2.4 KiB
Python
60 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import io
|
|
import base64
|
|
|
|
from PIL import Image
|
|
|
|
from odoo.tests.common import HttpCase
|
|
|
|
|
|
class TestImage(HttpCase):
|
|
def test_01_content_image_resize_placeholder(self):
|
|
"""The goal of this test is to make sure the placeholder image is
|
|
resized appropriately depending on the given URL parameters."""
|
|
|
|
# CASE: resize placeholder, given size but original ratio is always kept
|
|
response = self.url_open('/web/image/0/200x150')
|
|
image = Image.open(io.BytesIO(response.content))
|
|
self.assertEqual(image.size, (150, 150))
|
|
|
|
# CASE: resize placeholder to 128
|
|
response = self.url_open('/web/image/fake/0/image_128')
|
|
image = Image.open(io.BytesIO(response.content))
|
|
self.assertEqual(image.size, (128, 128))
|
|
|
|
# CASE: resize placeholder to 256
|
|
response = self.url_open('/web/image/fake/0/image_256')
|
|
image = Image.open(io.BytesIO(response.content))
|
|
self.assertEqual(image.size, (256, 256))
|
|
|
|
# CASE: resize placeholder to 1024 (but placeholder image is too small)
|
|
response = self.url_open('/web/image/fake/0/image_1024')
|
|
image = Image.open(io.BytesIO(response.content))
|
|
self.assertEqual(image.size, (256, 256))
|
|
|
|
# CASE: no size found, use placeholder original size
|
|
response = self.url_open('/web/image/fake/0/image_no_size')
|
|
image = Image.open(io.BytesIO(response.content))
|
|
self.assertEqual(image.size, (256, 256))
|
|
|
|
def test_02_content_image_Etag_304(self):
|
|
"""This test makes sure that the 304 response is properly returned if the ETag is properly set"""
|
|
|
|
attachment = self.env['ir.attachment'].create({
|
|
'datas': b"R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=",
|
|
'name': 'testEtag.gif',
|
|
'public': True,
|
|
'mimetype': 'image/gif',
|
|
})
|
|
response = self.url_open('/web/image/%s' % attachment.id, timeout=None)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(base64.b64encode(response.content), attachment.datas)
|
|
|
|
etag = response.headers.get('ETag')
|
|
|
|
response2 = self.url_open('/web/image/%s' % attachment.id, headers={"If-None-Match": etag})
|
|
self.assertEqual(response2.status_code, 304)
|
|
self.assertEqual(len(response2.content), 0)
|