当前位置:网站首页>SublimeText 粘贴图片保存到本地
SublimeText 粘贴图片保存到本地
2022-08-04 14:50:00 【林德熙】
在写 Markdown 时,比较难的是把图片粘贴保存到本地,或上传到服务器。 本文提供一个简单的方式可以把剪贴板的图片粘贴保存本地。
首先需要下载代码,打开 https://github.com/dotnet-campus/imagepaste 然后下载代码,可以使用 git 的方式下载
然后点击 SublimeText 的 Preference ,点击 Browse Package ,这时会弹出一个文件夹,文件夹的路径是C:\Users\用户名\AppData\Roaming\Sublime Text 3\Packages
在 SublimeText 安装包 imagepaste ,安装的方法是按下 ctrl+shift+p 然后输入 install ,选择 PackageControl:Install Package ,这时需要等一下才会出现弹出的输入。在弹出的输入,输入 imagepaste 就可以成功安装。
在安装完成之后,从刚才打开的文件夹可以看到 ImagePaste 文件夹,把下载下来的文件替换这个文件夹的文件就可以了。
这时尝试截图,然后粘贴,可以看到显示是
 如果需要修改保存的文件路径,那么需要修改 ImagePaste.py 文件,在开始修改,希望你有一些 py 开发的经验,如果没有的话,可能看不懂我在写什么
保存的路径在 get_filename 函数里面写,所以打开 get_filename 函数可以看到下面代码
def get_filename(self):
view = self.view
filename = view.file_name()
# create dir in current path with the name of current filename
dirname, _ = os.path.splitext(filename)
# create new image file under currentdir/filename_without_ext/filename_without_ext%d.png
fn_without_ext = os.path.basename(dirname)
gitbook_dir = os.path.split(dirname)[0]+'\\image\\'+fn_without_ext
if not os.path.lexists(gitbook_dir):
os.mkdir(gitbook_dir)
i = 0
while True:
# relative file path
rel_filename = os.path.join("%s/%s%d.png" % ("image/"+fn_without_ext, fn_without_ext, i))
# absolute file path
abs_filename = os.path.join(gitbook_dir, "%s%d.png" % ( fn_without_ext, i))
if not os.path.exists(abs_filename):
break
i += 1
print("save file: " + abs_filename + "\nrel " + rel_filename)
return abs_filename, rel_filename这里的 gitbook_dir 就是用来保存图片的绝对路径,rel_filename 就是用来放在文本的相对路径。
从代码gitbook_dir = os.path.split(dirname)[0]+'\\image\\'+fn_without_ext 可以把路径修改为 os.path.split(dirname)[0]文件所在文件夹路径下的 Image 文件夹的 fn_without_ext 去掉文件后缀名的文件夹。
从rel_filename = os.path.join("%s/%s%d.png" % ("image/"+fn_without_ext, fn_without_ext, i))可以拿到合并了image文件夹和fn_without_ext去掉后缀名的文件名作为文件夹的相对路径,所以里面的修改就十分简单了
例如我需要把代码修改保存在 assets 文件夹下,不需要加上文件名的文件夹,例如
assets/xx0.png那么可以这样修改
gitbook_dir = os.path.split(dirname)[0]+'\\assets'rel_filename = os.path.join("%s/%s%d.png" % ("assets/", fn_without_ext, i))边栏推荐
- MySQL优化学习笔记
- leetcode:212. 单词搜索 II
- Bluetooth Technology|In the first half of the year, 1.3 million charging piles were added nationwide, and Bluetooth charging piles will become the mainstream of the market
- How to automatically renew the token after it expires?
- How to Identify Asynchronous I/O Bottlenecks
- Makefile 语法及使用笔记
- Centos7 install mysql version rapidly
- 技术分享| 融合调度系统中的电子围栏功能说明
- 1403. Minimum Subsequence in Non-Increasing Order
- Android Sqlite3 basic commands
猜你喜欢

leetcode: 254. Combinations of factors

X射线掠入射聚焦反射镜

Database recovery

郑轻新生校赛和中工选拔赛题解

Zheng Qing freshmen school competition and middle-aged engineering selection competition

基于 Next.js实现在线Excel

大众点评搜索相关性技术探索与实践

leetcode:253. 至少需要多少间会议室
微软表示将向内部网络安全专家共享数据 为企业提供更安全保护

Cisco - Small Network Topology (DNS, DHCP, Web Server, Wireless Router)
随机推荐
化繁为简,聊一聊复制状态机系统架构抽象
C# 局部函数与事件
Rust from entry to proficient 04-variables
OAID是什么
数据库恢复
leetcode:212. 单词搜索 II
leetcode: 250. Count subtrees of equal value
This week to discuss the user experience: Daedalus Nemo to join Ambire, explore the encryption of the ocean
分布式链路追踪Jaeger + 微服务Pig在Rainbond上的实践分享
技术分享| 小程序实现音视频通话
1403. 非递增顺序的最小子序列
兆骑科创创新创业大赛活动举办,线上直播路演,投融资对接
Android Sqlite3基本命令
期货开户之前要谈好最低手续费和交返
SQL语句的写法:Update、Case、 Select 一起的用法
Leetcode: 215 disorderly to find the first big k element in the array
leetcode:253. 至少需要多少间会议室
F.金玉其外矩阵(构造)
关于pnpm包管理器的版本问题
Basic Introduction for PLSQL