From 822b05d1daa589b24839c93b7ad74ea48ec8d509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Mon, 20 May 2019 13:54:34 +0000 Subject: [PATCH] [IMP] tools: limit image quality to 95 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Values above 95 do not increase the quality but they disable optimizations that increase the file size unnecessarily. See `quality` parameter at https://pillow.readthedocs.io/en/4.0.x/handbook/image-file-formats.html#jpeg Part of task-1930726 closes odoo/odoo#33507 Signed-off-by: Jérémy Kersten (jke) --- odoo/tools/image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/odoo/tools/image.py b/odoo/tools/image.py index c7c58a11d03..b0e7e2ee7b7 100644 --- a/odoo/tools/image.py +++ b/odoo/tools/image.py @@ -228,6 +228,10 @@ class ImageProcess(): def image_process(base64_source, size=(0, 0), verify_resolution=False, quality=80, crop=None, colorize=False, output_format=None): """Process the `base64_source` image by executing the given operations and return the result as a base64 encoded image. + + As this function is exposed to users through controllers, the quality is + limited to 95 as per recommandation from PIL. If needed the lower level + method image_base64 in ImageProcess does not enforce that limit. """ image = ImageProcess(base64_source, verify_resolution) if size: @@ -243,7 +247,7 @@ def image_process(base64_source, size=(0, 0), verify_resolution=False, quality=8 image.resize(max_width=size[0], max_height=size[1]) if colorize: image.colorize() - return image.image_base64(quality=quality, output_format=output_format) + return image.image_base64(quality=min(quality, 95), output_format=output_format) # ----------------------------------------