How it works...

Odoo uses the PIL library for image processing. By default, the image_resize_images() method resizes the actual image to sizes of 1024 x 1024 px, 128 x 128 px, and 64 x 64 px. These are then stored in the image, image_medium, and image_small fields, respectively. This behavior, however, can be customized. Take a look at the image_resize_images() method signature:

def image_resize_images(vals, big_name='image', medium_name='image_medium', small_name='image_small', sizes={}):
...

In the given method signature, vals is the values dictionary sent from the write or create method. This dictionary will contain the actual image. The big_name, medium_name, and small_name parameters are used to define the field names in which the resized images will be returned. The sizes parameter is used to change the default image sizes. Let's say you want to save images into the image_lg, image_md, and image_sm fields with custom sizes. To do this, you can call the following methods:

sizes = {'image_lg': (1000, 1000),'image_md': (500x500),'image_sm': (50x50)}

tools.image_resize_images(vals, big_name='image_lg', medium_name='image_md', small_name='image_sm', sizes=sizes)

This will save the images into different fields and with different sizes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset