[FIX] tools: image.crop_image default type fix

- the image.crop_image method doesn't defaults the format to PNG anymore.
  Instead it uses the format of the original image
  and defaults to jpeg as a last resort as the save method requires
  a type if it is called with an image object.
This commit is contained in:
ThanhDodeurOdoo
2018-09-05 16:33:25 +02:00
parent e312ec71dd
commit fa39019ee1
+2 -1
View File
@@ -177,7 +177,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
@@ -206,6 +206,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)