diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-07-07 14:18:07 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-07-07 14:18:07 +0200 |
| commit | 0f2b2c4e2b99df8d68456016a4bea86e26c1c80e (patch) | |
| tree | 37ecc505ddb81ec1cd048dba9655e03e3176c546 /odoo/tools/image.py | |
| parent | 5241d479b222bc11ebd1c0ff41c38872a3fea8fd (diff) | |
| parent | 514a1a76d81de3943f752ceaa5e487a2d25b9bb7 (diff) | |
[MERGE] forward port branch saas-15 up to 514a1a76d81
Diffstat (limited to 'odoo/tools/image.py')
| -rw-r--r-- | odoo/tools/image.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/odoo/tools/image.py b/odoo/tools/image.py index bacf6a9c999..0ff50967f0a 100644 --- a/odoo/tools/image.py +++ b/odoo/tools/image.py @@ -75,7 +75,7 @@ def image_resize_image(base64_source, size=(1024, 1024), encoding='base64', file if image.size != size: image = image_resize_and_sharpen(image, size) - if image.mode not in ["1", "L", "P", "RGB", "RGBA"]: + if image.mode not in ["1", "L", "P", "RGB", "RGBA"] or (filetype == 'JPEG' and image.mode == 'RGBA'): image = image.convert("RGB") background_stream = StringIO.StringIO() @@ -92,6 +92,7 @@ def image_resize_and_sharpen(image, size, preserve_aspect_ratio=False, factor=2. :param preserve_aspect_ratio: boolean (default: False) :param factor: Sharpen factor (default: 2.0) """ + origin_mode = image.mode if image.mode != 'RGBA': image = image.convert('RGBA') image.thumbnail(size, Image.ANTIALIAS) @@ -102,6 +103,8 @@ def image_resize_and_sharpen(image, size, preserve_aspect_ratio=False, factor=2. # create a transparent image for background and paste the image on it image = Image.new('RGBA', size, (255, 255, 255, 0)) image.paste(resized_image, ((size[0] - resized_image.size[0]) / 2, (size[1] - resized_image.size[1]) / 2)) + if image.mode != origin_mode: + image = image.convert(origin_mode) return image def image_save_for_web(image, fp=None, format=None): |
