def _get_thumbnail(self): for record in self: if record.mimetype: if re.match('image.*(gif|jpeg|jpg|png)', record.mimetype): if not record.thumbnail: temp_image = crop_image(record.datas, type='center', size=(100, 100), ratio=(1, 1)) record.thumbnail = image_resize_image(base64_source=temp_image, size=(100, 100), encoding='base64', filetype='PNG')
def _make_thumbnail(self, vals): if vals.get('datas') and not vals.get('res_field'): vals['thumbnail'] = False if vals.get('mimetype') and re.match('image.*(gif|jpeg|jpg|png)', vals['mimetype']): try: temp_image = crop_image(vals['datas'], type='center', size=(80, 80), ratio=(1, 1)) vals['thumbnail'] = image_resize_image(base64_source=temp_image, size=(80, 80), encoding='base64') except Exception: pass return vals
def _get_thumbnail(self): for record in self: if record.mimetype: if re.match('image.*(gif|jpeg|jpg|png)', record.mimetype): if not record.thumbnail: temp_image = crop_image(record.datas, type='center', size=(100, 100), ratio=(1, 1)) record.thumbnail = image_resize_image( base64_source=temp_image, size=(100, 100), encoding='base64', filetype='PNG')
def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas', filename_field='datas_fname', unique=None, filename=None, mimetype=None, download=None, width=0, height=0, crop=False, access_token=None): status, headers, content = binary_content( xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename, filename_field=filename_field, download=download, mimetype=mimetype, default_mimetype='image/png', access_token=access_token) if status == 304: return werkzeug.wrappers.Response(status=304, headers=headers) elif status == 301: return werkzeug.utils.redirect(content, code=301) elif status != 200 and download: return request.not_found() if headers and dict(headers).get('Content-Type', '') == 'image/svg+xml': # we shan't resize svg images height = 0 width = 0 else: height = int(height or 0) width = int(width or 0) if crop and (width or height): content = crop_image(content, type='center', size=(width, height), ratio=(1, 1)) elif content and (width or height): # resize maximum 500*500 if width > 500: width = 500 if height > 500: height = 500 content = odoo.tools.image_resize_image(base64_source=content, size=(width or None, height or None), encoding='base64', filetype='PNG') # resize force png as filetype headers = self.force_contenttype(headers, contenttype='image/png') if content: image_base64 = base64.b64decode(content) else: image_base64 = self.placeholder(image='placeholder.png') # could return (contenttype, content) in master headers = self.force_contenttype(headers, contenttype='image/png') headers.append(('Content-Length', len(image_base64))) response = request.make_response(image_base64, headers) response.status_code = status return response
def _resize_thumbnail(self, image, crop=True): data = crop_image(image, type='center', size=(256, 256), ratio=(1, 1)) if crop else image return image_resize_image(base64_source=data, size=(256, 256), encoding='base64')