Example #1
0
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
Example #2
0
 def write(self, vals):
     if 'image' in vals:
         vals['image'] = image_resize_image_small(vals['image'])
     return super(MarketplaceSite, self).write(vals)