Hello Odooers, Odoogig and Odoo Lovers,
Today is Monday so i’m back with Amazing Odoo Technical Tutorial.
Being a odoo developer, Sometimes you need to read image from the module (addon) itself in odoo, So in this Odoo Technical Tutorial, I am going to show you how to read image from the module and assign image to the particular binary field in odoo
- If you do not know what is binary field in odoo then first refer this
img_path = get_module_resource('dev_image_demo', 'static/src/img', 'avatar.png')
with open(img_path, 'rb') as f:
image = f.read()
self.avatar = tools.image_resize_image_big(base64.b64encode(image))
#image #readimage #odoo #odoo12.0 #resizeimage
- In above example
- dev_image_demo is the name of the odoo module / odoo app name
- static/src/img is the path of the image inside the module. Like dev_image_demo > static > src > img > avatar.png
- self.avatar is the name of the binary field in which image will be assigned
- do not forget to import below two thing before using Example 1
from odoo.modules import get_module_resource
from odoo import models, api, tools
GET IN TOUCH.!
We’d Love to Hear from You! We are happy to answer any questions, you have regarding My Training.
Mail : firstname.lastname@example.org
Skype : mayur_maheshwari1
What’s app : +919924542042