Exemple #1
0
def get_src_from_data(data=None, html=False):
    """Base64 인코딩한 데이터를 반환한다.
    
    html 옵션이 True일 경우 HTML <img> 태그와 함께 반환한다.

    Reference:
        https://mindtrove.info/

    Arguments:
        data (string): image file path
    
    Returns:
        Base64-encoded file value

    Example:
        >>> get_src_from_data('image/chart.png')
    """
    if data:
        img_obj = Image(data=data)
        for bundle in img_obj._repr_mimebundle_():
            for mimetype, b64value in bundle.items():
                if mimetype.startswith('image/'):
                    encoded = f'data:{mimetype};base64,{b64value}'
                    if html:
                        return f'<img src="{encoded}">'
                    else:
                        return encoded
    else:
        if html:
            return "<span><i>Image Not Available</i></span>"
        else:
            return None
Exemple #2
0
def _src_from_data(data):
    """Base64 encodes image bytes for inclusion in an HTML img element"""
    img_obj = Image(data=data)
    for bundle in img_obj._repr_mimebundle_():
        for mimetype, b64value in bundle.items():
            if mimetype.startswith('image/'):
                return f'data:{mimetype};base64,{b64value}'