溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么使用draw.io插件在vscode中一體化導(dǎo)出高質(zhì)量圖片

發(fā)布時(shí)間:2022-08-08 15:19:46 來(lái)源:億速云 閱讀:1208 作者:iii 欄目:開(kāi)發(fā)技術(shù)

本文小編為大家詳細(xì)介紹“怎么使用draw.io插件在vscode中一體化導(dǎo)出高質(zhì)量圖片”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“怎么使用draw.io插件在vscode中一體化導(dǎo)出高質(zhì)量圖片”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來(lái)學(xué)習(xí)新知識(shí)吧。

vscode一體化導(dǎo)出drawio

需要的工具:vscode, draw.io擴(kuò)展,draw.io桌面版 、python

提示:這個(gè)方法并沒(méi)有簡(jiǎn)化流程,只是能夠減少打開(kāi)窗口,在vscode中直接查看原始文件,導(dǎo)出文件,效率并沒(méi)有顯著提升。

啰嗦的部分:
drawio流程圖繪制軟件比visio好用。而且vscode有插件。vs插件的優(yōu)點(diǎn)在于支持mermaid流程圖,缺點(diǎn)非常明顯不支持指定分辨率圖像導(dǎo)出。
網(wǎng)上檢索發(fā)現(xiàn)drawio的桌面版可以在命令行操作。在drawio安裝目錄下運(yùn)行cmd,然后通過(guò)draw.io -help 命令可以查看全部命令。
查看命令發(fā)現(xiàn)沒(méi)有針對(duì)性的dpi設(shè)置。我就想到給圖片輸入寬度和高度的方式。根據(jù)我猜測(cè)這個(gè)寬度和高度應(yīng)該對(duì)應(yīng)的就是像素點(diǎn)數(shù)量,所以我就按照實(shí)際尺寸,以及dpi的定義
寫(xiě)了一個(gè)命令, 發(fā)現(xiàn)可用。但是每次都要計(jì)算寬度、高度、調(diào)用cmd命令窗口,太麻煩。功能強(qiáng)大的python加上插件齊全的vscode能不能全部實(shí)現(xiàn)呢?
折騰了幾個(gè)小時(shí),終于搞定了。

進(jìn)入正題:
1、安裝draw.io插件,和桌面版,記住桌面版的路徑
2、繪制好的圖片有一個(gè)實(shí)際的尺寸,記住實(shí)際尺寸的寬和高
3、python轉(zhuǎn)換 寬度

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

4、 構(gòu)造命令行,不嫌麻煩可以自己寫(xiě)完整目錄

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文件工作目錄并執(zhí)行命令

path="D:/draw.io/"#安裝文件夾
os.chdir( path )# 修改當(dāng)前工作目錄
v2=os.system(commandtext1)

完整的代碼

代碼量并不大,非常簡(jiǎn)單

'''
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 )# 修改當(dāng)前工作目錄
v2=os.system(commandtext1)

# 快速運(yùn)行F5
# print(v2)

#關(guān)于python權(quán)限的問(wèn)題
# https://blog.csdn.net/qq_33731081/article/details/103812749
# 如何在python中運(yùn)行命令行命令
# https://blog.csdn.net/qq_34769162/article/details/119037908
#報(bào)錯(cuò)為空值的問(wèn)題
# https://blog.csdn.net/xiaoxiaogh/article/details/88320102

#關(guān)于drawio導(dǎo)出命令,靈感來(lái)源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中一體化導(dǎo)出高質(zhì)量圖片”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過(guò)才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI