From 08cda70147bb8160136756b5175513bcd35aff75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Tue, 4 Jun 2019 15:10:13 +0200 Subject: [PATCH] [FIX] tools: fix support for multi-frame GIF images Before this commit, only the first frame would be saved. PR: #31208 --- odoo/tools/image.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/odoo/tools/image.py b/odoo/tools/image.py index b0e7e2ee7b7..6367f9b158b 100644 --- a/odoo/tools/image.py +++ b/odoo/tools/image.py @@ -119,6 +119,7 @@ class ImageProcess(): opt['quality'] = quality if output_format == 'GIF': opt['optimize'] = True + opt['save_all'] = True if output_image.mode not in ["1", "L", "P", "RGB", "RGBA"] or (output_format == 'JPEG' and output_image.mode == 'RGBA'): output_image = output_image.convert("RGB") @@ -136,6 +137,9 @@ class ImageProcess(): If `max_width` or `max_height` is falsy, it will be computed from the other to keep the current ratio. If both are falsy, no resize is done. + It is currently not supported for GIF because we do not handle all the + frames properly. + :param max_width: max width :type max_width: int @@ -145,7 +149,7 @@ class ImageProcess(): :return: self to allow chaining :rtype: ImageProcess """ - if self.image and (max_width or max_height): + if self.image and self.image.format != 'GIF' and (max_width or max_height): w, h = self.image.size asked_width = max_width or (w * max_height) // h asked_height = max_height or (h * max_width) // w @@ -168,6 +172,9 @@ class ImageProcess(): original image. If the latter is what you want to do, you should create another method, or directly use the `crop` method from PIL. + It is currently not supported for GIF because we do not handle all the + frames properly. + :param max_width: max width :type max_width: int @@ -185,7 +192,7 @@ class ImageProcess(): :return: self to allow chaining :rtype: ImageProcess """ - if self.image and max_width and max_height: + if self.image and self.image.format != 'GIF' and max_width and max_height: w, h = self.image.size # We want to keep as much of the image as possible -> at least one # of the 2 crop dimensions always has to be the same value as the