iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >如何使用draw.io插件在vscode中一体化导出高质量图片
  • 660
分享到

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

2024-04-02 19:04:59 660人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

‘’’Author: zzxDate: 2022-07-30 15:52:15LastEditors: zdlLastEditTime: 2022

‘’’
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转换 宽度

dpivalue=600#dpi
realwidth=89.4#mm
realheight=81.2#mm
width=round(dpivalue*realwidth/25.4)
height=round(dpivalue*realheight/25.4)

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

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

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

完整的代码

代码量并不大,非常简单

'''
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一体化导出图片内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

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

本文链接: https://www.lsjlt.com/news/119832.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作