Skip to content
Snippets Groups Projects
Commit 66e2aeb6 authored by ThanhDodeurOdoo's avatar ThanhDodeurOdoo Committed by Nans Lefebvre
Browse files

[FIX] tools: image.crop_image default type fix


Backport of fa39019e.
If crop_image is called without a default format, it would try the default,
'PNG', to save the result and crash at save when processing non-PNG images.
For example, if a jpeg image was in CMYK colors.

Here it will still crash non-gracefully when failing to save, but the default
should almost always work; if it doesn't it means we failed to detect the format
of the stream, so it is unlikely that we could save the image anyway.

opw 2009029

closes odoo/odoo#34088

Signed-off-by: default avatarNans Lefebvre (len) <len@odoo.com>
parent ec8c6699
Branches
Tags
No related merge requests found
......@@ -159,7 +159,7 @@ def image_resize_image_small(base64_source, size=(64, 64), encoding='base64', fi
# ----------------------------------------
# Crop Image
# ----------------------------------------
def crop_image(data, type='top', ratio=False, size=None, image_format="PNG"):
def crop_image(data, type='top', ratio=False, size=None, image_format=None):
""" Used for cropping image and create thumbnail
:param data: base64 data of image.
:param type: Used for cropping position possible
......@@ -188,6 +188,7 @@ def crop_image(data, type='top', ratio=False, size=None, image_format="PNG"):
new_h = h
new_w = (h * w_ratio) // h_ratio
image_format = image_format or image_stream.format or 'JPEG'
if type == "top":
cropped_image = image_stream.crop((0, 0, new_w, new_h))
cropped_image.save(output_stream, format=image_format)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment