Skip to content

Instantly share code, notes, and snippets.

@sehrishnaz
Created July 17, 2020 05:17
Show Gist options
  • Select an option

  • Save sehrishnaz/6ada0a6876886c2b23cb863fd7992ec7 to your computer and use it in GitHub Desktop.

Select an option

Save sehrishnaz/6ada0a6876886c2b23cb863fd7992ec7 to your computer and use it in GitHub Desktop.
Resize existing image record in Odoo
from openerp import tools
class YourModelName(models.Model):
_name = 'your.model.name'
image = fields.Binary(string="Picture",required=True)
image_name = fields.Char("Picture Name")
@api.model
def create(self,values):
if 'image' in values:
# resize uploaded image into 250 X 250
resize_image = tools.image_resize_image(values['image'], size=(250, 250), avoid_if_small=True)
values['image'] = resize_image
return super(YourModelName, self).create(values)
@api.multi
def write(self, values):
if 'image' in values:
# resize uploaded image into 250 X 250
resize_image = tools.image_resize_image(values['image'], size=(250, 250), avoid_if_small=True)
values['image'] = resize_image
return super(YourModelName, self).write(values)
@sehrishnaz
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment