From 7768abd40bb6c58bafc9397dbf2cf6ba9dadc1cc Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 24 Aug 2018 14:31:45 +0200 Subject: [PATCH] [FIX] tools:image: reset stream on crop When cropping the image with a size, we crop it first and then we make a thumbnail out of it Before this commit, the same byte stream was used, meaning that the thumbnail was appended to the original After this commit, we reset the stream OPW 1876496 closes #26575 --- odoo/tools/image.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/odoo/tools/image.py b/odoo/tools/image.py index 24da52b3c81..2b1cbed1860 100644 --- a/odoo/tools/image.py +++ b/odoo/tools/image.py @@ -201,6 +201,8 @@ def crop_image(data, type='top', ratio=False, size=None, image_format="PNG"): raise ValueError('ERROR: invalid value for crop_type') if size: thumbnail = Image.open(io.BytesIO(output_stream.getvalue())) + output_stream.truncate(0) + output_stream.seek(0) thumbnail.thumbnail(size, Image.ANTIALIAS) thumbnail.save(output_stream, image_format) return base64.b64encode(output_stream.getvalue())