gpt4 book ai didi

svg - 在 Inkscape 中将 SVG 批量转换为 PNG 不起作用

转载 作者:行者123 更新时间:2023-12-04 21:36:42 24 4
gpt4 key购买 nike

我想转换文件夹 C:\Users\Eric\Desktop\svg 中的多个 SVG 文件到名称为 [SVG File Name].svg.png 的 512x512 PNG 文件.

我尝试了以下命令:for /f %f in ('dir /b "C:\Users\Eric\Desktop\svg"') do inkscape -z -e %f.png -w 512 -h 512 %f
命令行正确检测 SVG 文件并通过它们,但 Inkscape 显示以下内容:

C:\Users\Eric\Desktop\inkscape>inkscape -z -e [SVG File Name].svg.png -w 512 -h 512 [SVG File Name].svg

** (inkscape.exe:8412): WARNING **: Can't open file: [SVG File Name].svg (doesn't exist)

** (inkscape.exe:8412): WARNING **: Can't open file: [SVG File Name].svg (doesn't exist)

** (inkscape.exe:8412): WARNING **: Specified document [SVG File Name].svg cannot be opened (does not exist or not a valid SVG file)

我在普通的 Inkscape 程序中打开了一个文件,它工作正常。

最佳答案

对于 SVG 到 PNG 的转换,我发现 cairosvg ( https://cairosvg.org/ ) 的性能比 ImageMagick 好。在目录中的所有文件上安装和运行的步骤。

pip3 install cairosvg

在包含 .svg 文件的目录中打开一个 python shell 并运行:
import os

for file in os.listdir('.'):
name = file.split('.svg')[0]
cairosvg.svg2png(url=name+'.svg',write_to=name+'.png')

这也将确保您不会覆盖原始 .svg 文件,但会保持相同的名称。然后,您可以使用以下命令将所有 .png 文件移动到另一个目录:
$ mv *.png [new directory]

关于svg - 在 Inkscape 中将 SVG 批量转换为 PNG 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36197664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com