def image_shape(self, module, filename, img_key, **kwargs): svg = self._get_shape_svg(module, 'image_shapes', filename) _, _, image_base64 = request.env['ir.http'].binary_content( xmlid=img_key, model='ir.attachment', field='datas', default_mimetype='image/png') if not image_base64: image_base64 = b64encode(Binary.placeholder()) image = base64_to_image(image_base64) width, height = tuple(str(size) for size in image.size) root = etree.fromstring(svg) root.attrib.update({'width': width, 'height': height}) # Update default color palette on shape SVG. svg, _ = self._update_svg_colors( kwargs, etree.tostring(root, pretty_print=True).decode('utf-8')) # Add image in base64 inside the shape. uri = image_data_uri(image_base64) svg = svg.replace('<image xlink:href="', '<image xlink:href="%s' % uri) return request.make_response(svg, [ ('Content-type', 'image/svg+xml'), ('Cache-control', 'max-age=%s' % http.STATIC_CACHE_LONG), ])
def get_avatar(self, access_token=None, share_id=None): """ :param share_id: id of the share. :param access_token: share access token :returns the picture of the share author for the front-end view. """ try: env = request.env share = env['documents.share'].sudo().browse(share_id) if share._get_documents_and_check_access( access_token, document_ids=[], operation='read') is not False: image = env['res.users'].sudo().browse( share.create_uid.id).image_128 if not image: binary = Binary() return binary.placeholder() return base64.b64decode(image) else: return request.not_found() except Exception: logger.exception("Failed to download portrait") return request.not_found()
def resize_to_48(b64source): if not b64source: b64source = base64.b64encode(Binary.placeholder()) return image_process(b64source, size=(48, 48))