【问题标题】:inkscape to convert svg -> png: pagesize?inkscape 转换 svg -> png: pagesize?
【发布时间】:2012-09-05 19:54:49
【问题描述】:

我需要在命令行将 svg 转换为 png。我尝试使用 imagemagick 但与旋转变换一起使用时似乎有一个错误,例如此示例 s3.svg:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg">
  <g id="layer1">
    <circle cx="200" cy="200" r="200" stroke="black"
        stroke-width="0.5" fill="none"/>
    <g transform="rotate(48 200 200)">
      <path id="path00" style="fill:#dca08c;stroke:#000000;stroke-width:1"
         d="M 200,0 L 400,200 L 200,400 L 0,200 z"/>
    </g>
  </g>
</svg>

我可以在命令行中使用 inkscape:

  c:\app\inkscape\portable\App\Inkscape\inkscape.com -f s3.svg -e s3.png --export-background=white --export-area=0:652:400:1052

但 SVG 坐标 (0,0) 定义在左上角,而在 inkscape 的导出中,导出区域 (0,0) 定义在左下角。

如何在没有定义页面高度的幻数 1052 的情况下使用 inkscape 导出?

【问题讨论】:

  • 我对 InkScape 了解不多,但documentation 似乎非常直接
  • Imagemagick 在我的环境中工作,与 inkscape 给出的输出相同。能给出你使用的命令行吗?
  • 这是一个怎样的编程问题?
  • SVG 不是来自 inkscape。我正在“编程”(是的,松散的解释)使用 SVG 绘制图像,然后使用 inkscape 命令行“以编程方式”从 svg 创建一个 png 图像。如果我可以调整 SVG 或命令行语法来获得我需要的东西,那将解决我的问题。
  • 你有没有找到直接访问页面大小的方法?

标签: svg png inkscape


【解决方案1】:

看来您要导出的是整个绘图。

inkscape 可以选择使用--export-area-drawing 导出绘图,而不是指定要导出的区域。

c:\app\inkscape\portable\App\Inkscape\inkscape.com -f s3.svg -e s3.png --export-background=white --export-area-drawing

【讨论】:

  • +1 用于发现...但我仍然想选择要导出的确切区域。
【解决方案2】:

如果问题是不知道页面高度,那么下面的语法可能会有所帮助?

c:\app\inkscape\portable\App\Inkscape\inkscape.com s3.svg -z --query-height

这应该返回文档的像素高度,您可以在导出调用中使用返回的数字。

【讨论】:

  • 不,它返回绘图的高度。来自inkscape --helpQuery the height of the drawing or, if specified, of the object with --query-id
【解决方案3】:

一种可能有帮助的方法是绘制一个您想要作为容器的区域,给它一个 id,然后使用 -i id 选项将其导出。如果它不应该是可见的,给包装器空白背景/边框。

编辑(添加示例): 我用过这个xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg">
  <g id="layer1">
    <rect width="400" height="600" id="wrapper" fill="none"></rect>
    <circle cx="200" cy="200" r="200" stroke="black"
        stroke-width="0.5" fill="none"/>
    <g transform="rotate(48 200 200)">
      <path id="path00" style="fill:#dca08c;stroke:#000000;stroke-width:1"
         d="M 200,0 L 400,200 L 200,400 L 0,200 z"/>
    </g>
  </g>
</svg>

使用这个命令(我在 Mac 上,所以根据需要翻译特定的操作系统)我可以控制输出 png 的大小/位置:

/Applications/Inkscape.app/Contents/Resources/bin/inkscape -f test.svg -e out.png -i wrapper

我不是 svg 专家,所以我不确定inkscape 是否有一些特定的功能,但我一直觉得它非常符合网络标准。过去我直接在网页中使用它的 svg 文件。

【讨论】:

  • 图像不是来自 inkscape,我可以在 xml 本身中执行此操作吗?
  • 是的,我可以使用上面的 xml 示例完成此操作,保存到文件中,并使用以下命令调用:-f test.svg -e out.png -i layer1
【解决方案4】:

Inkscape 有画布大小选项,我在为网络导出时遇到了同样的问题 - 你的图像从视口中掉了出来。

更改画布/画板大小以满足您要导出的元素的大小

【讨论】:

  • SVG 不是 来自 Inkscape。
  • 我可以在 svg xml 本身中指定它吗?
猜你喜欢
  • 1970-01-01
  • 2014-04-08
  • 2016-04-16
  • 1970-01-01
  • 2016-07-11
  • 1970-01-01
  • 2016-10-12
  • 1970-01-01
  • 2020-05-31
相关资源
最近更新 更多