脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - 如何使用draw.io插件在vscode中一体化导出高质量图片

如何使用draw.io插件在vscode中一体化导出高质量图片

2022-08-07 10:00zdlwhereyougo Python

这篇文章主要介绍了draw.io插件在vscode中一体化导出高质量图片需要的工具是vscode, draw.io扩展,draw.io桌面版 、python,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴,需要的朋友可以参考下

‘’’
Author: zzx
Date: 2022-07-30 15:52:15
LastEditors: zdl
LastEditTime: 2022-07-30 16:03:20
FilePath: \matlabcodef:\BaiduNetdiskWorkspace\markdown写杂谈\python导出drawio文件
Description:

Copyright © 2022 by zdl, All Rights Reserved.
‘’’

vscode一体化导出drawio

需要的工具:vscode, draw.io扩展,draw.io桌面版 、python

提示:这个方法并没有简化流程,只是能够减少打开窗口,在vscode中直接查看原始文件,导出文件,效率并没有显著提升。

啰嗦的部分:
drawio流程图绘制软件比visio好用。而且vscode有插件。vs插件的优点在于支持mermaid流程图,缺点非常明显不支持指定分辨率图像导出。
网上检索发现drawio的桌面版可以在命令行操作。在drawio安装目录下运行cmd,然后通过draw.io -help 命令可以查看全部命令。
查看命令发现没有针对性的dpi设置。我就想到给图片输入宽度和高度的方式。根据我猜测这个宽度和高度应该对应的就是像素点数量,所以我就按照实际尺寸,以及dpi的定义
写了一个命令, 发现可用。但是每次都要计算宽度、高度、调用cmd命令窗口,太麻烦。功能强大的python加上插件齐全的vscode能不能全部实现呢?
折腾了几个小时,终于搞定了。

进入正题:
1、安装draw.io插件,和桌面版,记住桌面版的路径
2、绘制好的图片有一个实际的尺寸,记住实际尺寸的宽和高
3、python转换 宽度

?
1
2
3
4
5
dpivalue=600#dpi
realwidth=89.4#mm
realheight=81.2#mm
width=round(dpivalue*realwidth/25.4)
height=round(dpivalue*realheight/25.4)

4、 构造命令行,不嫌麻烦可以自己写完整目录

?
1
2
3
4
5
inputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大论文\drawio\算法流程图.drawio'
outputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大论文\drawio\test.png'
starttext=r'draw.io -x '
midletext=r" -f png -t --width "+str(width)+r" --height " +str(height)+r" -o "
commandtext1=starttext+inputfilepath+midletext+outputfilepath

5、 改变python文件工作目录并执行命令

?
1
2
3
path="D:/draw.io/"#安装文件夹
os.chdir( path )# 修改当前工作目录
v2=os.system(commandtext1)

完整的代码

代码量并不大,非常简单

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'''
Author: zzx
Date: 2022-07-27 10:12:38
LastEditors: zdl
LastEditTime: 2022-07-30 16:10:22
FilePath: \matlabcodef:\BaiduNetdiskWorkspace\00typora\大论文\drawio\output.py
Description:
 
Copyright (c) 2022 by zdl, All Rights Reserved.
'''
import os
dpivalue=600#dpi
realwidth=89.4#mm
realheight=81.2#mm
width=round(dpivalue*realwidth/25.4)
height=round(dpivalue*realheight/25.4)
inputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大论文\drawio\算法流程图.drawio'
outputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大论文\drawio\test.png'
starttext=r'draw.io -x '
midletext=r" -f png -t --width "+str(width)+r" --height " +str(height)+r" -o "
commandtext1=starttext+inputfilepath+midletext+outputfilepath
path="D:/draw.io/"#安装文件夹
os.chdir( path )# 修改当前工作目录
v2=os.system(commandtext1)
 
# 快速运行F5
# print(v2)
 
#关于python权限的问题
# https://blog.csdn.net/qq_33731081/article/details/103812749
# 如何在python中运行命令行命令
# https://blog.csdn.net/qq_34769162/article/details/119037908
#报错为空值的问题
# https://blog.csdn.net/xiaoxiaogh/article/details/88320102
 
#关于drawio导出命令,灵感来源https://j2r2b.github.io/2019/08/06/drawio-cli.html
'''
Options:
  -V, --version                      output the version number
  -c, --create                       creates a new empty file if no file is
                                     passed
  -k, --check                        does not overwrite existing files
  -x, --export                       export the input file/folder based on the
                                     given options
  -r, --recursive                    for a folder input, recursively convert
                                     all files in sub-folders also
  -o, --output <output file/folder>  specify the output file/folder. If
                                     omitted, the input file name is used for
                                     output with the specified format as
                                     extension
  -f, --format <format>              if output file name extension is
                                     specified, this option is ignored (file
                                     type is determined from output extension,
                                     possible export formats are pdf, png, jpg,
                                     svg, vsdx, and xml) (default: "pdf")
  -q, --quality <quality>            output image quality for JPEG (default:
                                     90)
  -t, --transparent                  set transparent background for PNG
  -e, --embed-diagram                includes a copy of the diagram (for PNG,
                                     SVG and PDF formats only)
  --embed-svg-images                 Embed Images in SVG file (for SVG format
                                     only)
  -b, --border <border>              sets the border width around the diagram
                                     (default: 0)
  -s, --scale <scale>                scales the diagram size
  --width <width>                    fits the generated image/pdf into the
                                     specified width, preserves aspect ratio.
  --height <height>                  fits the generated image/pdf into the
                                     specified height, preserves aspect ratio.
  --crop                             crops PDF to diagram size
  -a, --all-pages                    export all pages (for PDF format only)
  -p, --page-index <pageIndex>       selects a specific page, if not specified
                                     and the format is an image, the first page
                                     is selected
  -g, --page-range <from>..<to>      selects a page range (for PDF format only)
  -u, --uncompressed                 Uncompressed XML output (for XML format
                                     only)
  --enable-plugins                   Enable Plugins
  -h, --help                         display help for command
'''

到此这篇关于draw.io插件在vscode中一体化导出高质量图片的文章就介绍到这了,更多相关draw.io vscode一体化导出图片内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/weixin_39361931/article/details/126073760

延伸 · 阅读

精彩推荐
  • PythonPython3利用Dlib实现摄像头实时人脸检测和平铺显示示例

    Python3利用Dlib实现摄像头实时人脸检测和平铺显示示例

    这篇文章主要介绍了Python3利用Dlib实现摄像头实时人脸检测和平铺显示示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学...

    coneypo8112021-05-31
  • Pythonpython实现对输入的密文加密

    python实现对输入的密文加密

    这篇文章主要为大家详细介绍了python实现对输入的密文加密,分析python求解简单加密问题,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    Together_CZ6402021-06-07
  • Python使用Python编写Prometheus监控的方法

    使用Python编写Prometheus监控的方法

    今天小编就为大家分享一篇关于使用Python编写Prometheus监控的方法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小...

    数据架构师5322021-04-08
  • PythonPython装饰器的执行过程实例分析

    Python装饰器的执行过程实例分析

    这篇文章主要介绍了Python装饰器的执行过程,结合实例形式分析了Python装饰器的原理、执行过程及相关操作注意事项,需要的朋友可以参考下...

    有一种宿命叫无能为力3982021-02-28
  • PythonPython数据类型之Dict字典实例详解

    Python数据类型之Dict字典实例详解

    这篇文章主要介绍了Python数据类型之Dict字典,结合具体实例形式详细分析了Python字典的概念、原理、定义、元素添加、删除、遍历等相关操作技巧,需要的朋...

    12573090546982021-06-24
  • Pythonpython3调用c语言代码的全过程记录

    python3调用c语言代码的全过程记录

    python调用c语言代码的方式十分简单,只需四步。下面这篇文章就来给大家详细介绍了关于python3如何调用c语言代码的相关资料,需要的朋友可以参考下...

    crazy_baoli7982021-11-01
  • PythonPython利用folium实现地图可视化

    Python利用folium实现地图可视化

    Folium是建立在Python生态系统的数据整理(Datawrangling)能力和Leaflet.js库的映射能力之上的开源库。这篇文章主要给大家介绍了关于如何Python利用folium实现地...

    Harris-H5762021-11-11
  • Pythonpython遍历数组的方法小结

    python遍历数组的方法小结

    这篇文章主要介绍了python遍历数组的方法,实例总结了两种Python遍历数组的技巧,非常具有实用价值,需要的朋友可以参考下 ...

    重负在身20222020-06-18