Markdown图片转代码形式插入
python代码
.
import base64
import pyperclip
import os
print('please input the image:\n')
image = input()
#image = 'image-20201226202430206.png'
with open(image,'rb') as f:
ls_f=base64.b64encode(f.read())
typ = image[-3:]
md = '![avatar](data:image/'+typ+';base64,'
base = str(ls_f)
if base[-2]=='=':
base_code = base[2:-3]
else:
base_code = base[2:-2]
done_code=md+base_code+')'
pyperclip.copy(done_code)
print("Done copy!......\n")
os.system('pause')
使用pyinstaller
进行打包,生成 exe
文件方便使用。
进入python文件所在目录,输入:
pyinstaller -F demo.py
如图所示:
之后会在dist文件夹里生成可执行文件demo.exe
双击运行,然后拖拽图片至该命令行界面,点击回车,base64代码将自动复制到剪切板上,直接复制到Markdown文件上即可。
效果如下:
显示图: