import base64


def pictourl(pic):
    """
    turn bytes into data URL
    """
    if pic.startswith(b'\x89\x50\x4e\x47\r\n\x1a\n'): # PNG signature
        return b"data:image/png;base64," + base64.b64encode(pic)
    if pic.startswith(b'\xff\xd8'):
        return b"data:image/jpeg;base64," + base64.b64encode(pic)
    return b"data:,Unknown%20file%20format"