# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name  : format_transfer.py
# @Time       : 2021/1/6 下午7:58
# @Author     : X. Peng
# @Email      : acepengxiong@163.com
# @Software   : PyCharm
# -----------------------------------------------------------------------------
import base64
import decimal
import json
import numpy as np

class npEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, np.ndarray):
            return obj.tolist()
        elif isinstance(obj, decimal.Decimal):
            return obj.__str__()
        elif isinstance(obj, np.int64):
            return int(obj)
        elif isinstance(obj, np.float64):
            return float(obj)
        return json.JSONEncoder.default(self, obj)

def img_transfer(url):
    """"""
    img_content = 'data:image/png;base64,'
    with open(url, 'rb') as f:
        img_content += base64.b64encode(f.read()).decode('utf-8')
    return img_content
