Created
July 17, 2020 05:17
-
-
Save sehrishnaz/6ada0a6876886c2b23cb863fd7992ec7 to your computer and use it in GitHub Desktop.
Resize existing image record in Odoo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For details: http://learnopenerp.blogspot.com/2020/07/how-to-resize-image-on-saving-records-in-odoo.html