def image_get_resized_images(base64_source, return_big=False, return_medium=True, return_small=True, big_name='image', medium_name='image_medium', small_name='image_small', avoid_resize_big=True, avoid_resize_medium=False, avoid_resize_small=False): """ Standard tool function that returns a dictionary containing the big, medium and small versions of the source image. This function is meant to be used for the methods of functional fields for models using images. Default parameters are given to be used for the getter of functional image fields, for example with res.users or res.partner. It returns only image_medium and image_small values, to update those fields. :param base64_source: base64-encoded version of the source image; if False, all returnes values will be False :param return_{..}: if set, computes and return the related resizing of the image :param {..}_name: key of the resized image in the return dictionary; 'image', 'image_medium' and 'image_small' by default. :param avoid_resize_[..]: see avoid_if_small parameter :return return_dict: dictionary with resized images, depending on previous parameters. """ return_dict = dict() if return_big: return_dict[big_name] = toolsImage.image_resize_image_big(base64_source,size=(1024, 1024), avoid_if_small=avoid_resize_big) if return_medium: return_dict[medium_name] = toolsImage.image_resize_image_medium(base64_source,size=(310, 310), avoid_if_small=avoid_resize_medium) if return_small: return_dict[small_name] = toolsImage.image_resize_image_small(base64_source,size=(150, 150), avoid_if_small=avoid_resize_small) return return_dict
from odoo.tools import image, base64 from odoo.modules import get_module_resource image_path = get_module_resource('hr', 'static/src/img', 'default_image.png') img = image.image_resize_image_big( base64.b64encode(open(image_path, 'rb').read())) resized_image = image.image_resize_image(base64_source=img, size=(500, 500)) ''' @api.depends('partner_id', 'partner_id.image') def _compute_logo_web(self): for company in self: company.logo_web = tools.image_resize_image(company.partner_id.image, (180, None)) ''' image.image_resize_images(vals={'some_fields': 1234}, sizes={'image': (1024, None)}) ''' Update ``vals`` with image fields resized as expected. @api.model_create_multi def create(self, vals_list): for vals in vals_list: tools.image_resize_images(vals) return super(FleetVehicleModelBrand, self).create(vals_list) ''' image.image_resize_and_sharpen(image=img, size=(500, 500)) image.image_get_resized_images(base64_source=img) '''