MarkDown 插入图片 && Picture To Base64

MarkDown 插入图片 && Picture To Base64

插入图片

  1. 本地插入图片

    不好分享, 本地图片路径更改和丢失, 都会导致图片无法加载

    ![text](/home/picture/0.png)
    
  2. 插入网络图片

    插入网络链接即可, 需将图片先上传至图床.
    ![text](http://xxxxxxx)
    
  3. 插入图片的Base64码

    ![text](data:image/png;base64,iVBORwo...)
    
    base64字符串过于长, 可在末尾设置一个id来调用
    ![text][id_0]
    [id_0]:data:image/png;base64,iVBORwo...
    

Picture to Base64

  1. 一些在线网站即可将Picture转Base64
    https://tool.chinaz.com/tools/imgtobase

  2. Python代码

    import 
    """
        Picture to Base64
    """
    file = open('/home/picture/0.png', 'rb') # 二进制只读方式打开文件  
    base_file = base64.b64encode(file.read())  
    file.close()
    txt = open('/home/picture/0.txt', 'wb') 
    txt.write(str(base_file))
    txt.clost()
    
    """
        Base64 to Picture
    """
    base_file = 'fasDWkkS.....'
    imgData = base64.b64decode(base_file)
    file = open('/home/picture/1.png', 'wb')
    file.write(imgData)
    file.close()
    
posted @ 2020-09-13 16:59  willwuss  阅读(1892)  评论(0编辑  收藏  举报