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()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM