import base64


def wrap_image_base64(img_path, trailing_br=False, **kwargs):
    """Wrap base64 image from a file. Return a <img> markup."""
    _width = kwargs.get('width', '')
    _style = kwargs.get('style', '')
    
    if _style != '':
        _style = ' style="' + _style + '"'
    
    if str(_width) != '' : _width = ' width='+str(_width)
    else                 : _width = ''
    
    img_base64 = open(img_path, 'rb').read()    # read bytes from file
    img_base64 = base64.b64encode(img_base64)   # encode to base64 (bytes)
    img_base64 = img_base64.decode()            # convert bytes to string
    
    txt = '<img src="data:image/jpeg;base64,' + img_base64 +'" ' + _width + _style + '></img>'
    if trailing_br:
        txt = txt + '<br>'
    return txt