【发布时间】:2023-02-21 09:45:24
【问题描述】:
蟒蛇 3.9.0 墨景0.92
我使用 Inkscape 将 SVG 转换为 EMF,但这需要太多时间。
简单示例代码
import subprocess
def convert_svg_to_emf(input_svg_path, output_emf_path):
# This method takes ~1 seconds
subprocess.run([
"C:\\Inkscape\\Inkscape.exe", # Inkscape executor path
input_svg_path, # Input SVG file
"--export-emf",
output_emf_path # Output EMF file
])
# Assume I have 100 files to convert
for i in range(100):
convert_svg_to_emf(f"svg{i}.svg", f"emf{i}.emf")
# This script takes ~100 seconds
虽然它取决于输入文件,但每次调用 'convert_svg_to_emf' 至少需要几秒钟。但是当我尝试直接从 Inkscape 转换它时,输出文件几乎立即出现。所以我假设应用程序的“打开”和“退出”子进程运行收取大部分处理时间。
有什么方法可以让它更快吗?
我的期待
inkscape = open_inkscape() # Keep opening Inkscape app
for i in range(100):
inkscape.convert_svg_to_emf(f"svg{i}.svg", f"emf{i}.emf")
inkscape.quit() # Quit the app after all work done
# This script conducts 'opening' and 'quitting' just once regardless of number of files.
【问题讨论】:
标签: python python-3.x subprocess inkscape