使用 ImageMagick 将 SVG 转换为 PNG 不处理 defs? [英] SVG to PNG Conversion with ImageMagick doesn't handle defs?

查看:48
本文介绍了使用 ImageMagick 将 SVG 转换为 PNG 不处理 defs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

答案在我标记的答案中,但在评论中.基本上,请参见此处: 并且符号不起作用.所以我倾向于 Imagemagick 是罪魁祸首.

更新:我尝试将 def 更改为以下内容:

在浏览器中,箭头会向右移动 25,但在 Imagemagick 中它会停留在 (0,0).这让我相信这与符号定义无关,而更多的是关于它没有正确翻译.但是,即使我尝试对使用"进行直接变换,甚至更好的是完全删除使用",箭头仍然会出现.

解决方案

更新: 这似乎是 ImageMagick 中默认 SVG 渲染器中的一个错误,它忽略了 xyuse 标签上(也忽略 g 标签上的转换属性).尝试改用 rsvg 后端.

如果你改变它是否有效:

<use xlink:href="#arrow" x="20" y="50"></use>

致:

<use xlink:href="#arrow"></use>

The answer is on the answer I flagged, but is in the comments. Basically, see here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=18816

Run this on Mac with Ports:

sudo port install ImageMagick +rsvg

Here's my original Question:

My test.svg file is here: https://gist.github.com/2727243

Imagemagick version: ImageMagick 6.7.6-9 2012-05-18 Q16 (just updated today)

I have a SVG file the does a defs -> symbol to define an arrow symbol. Later on in the document I xlink:use that symbol. This works fine in Chrome and the arrow comes up and is in its proper position:

However, if I convert the image via imagemagick like so:

convert test.svg test.png

It doesn't work. Here's what I get:

The "use" appears to be ignored completely, and instead the arrow is rendering at the def. At least, near as I can tell.

Am I formatting my SVG wrong for Imagemagick to handle this scenario? Or is this just something that Imagemagick doesn't support properly? I've been looking all over for a definitive answer and can't find one, one way or the other.

I also tried the SVG here: http://www.carto.net/svg/samples/symbol.svg and the symbols did NOT work. So I'm leaning toward Imagemagick being the culprit.

UPDATE: I tried changing the def to the following:

<symbol id="arrow" x="25">

In the browser, the arrow DOES move 25 to the right, but in Imagemagick it sticks to (0,0). This was leading me to believe that it's less about the symbol definition and more about it not translating it properly. However, even if I try a straight transform on the "use" and, even better, remove the "use" entirely, the arrow still appears.

解决方案

Update: This seams to be a bug in the default SVG renderar in ImageMagick that ignores x and y on use tags (and also ignores transform attributes on g tags). Try to use the rsvg backend instead.

Does it work if you change:

<use xlink:href="#arrow" x="20" y="50"></use>

To:

<g transform="translate(20 50)">
  <use xlink:href="#arrow"></use>
</g>

这篇关于使用 ImageMagick 将 SVG 转换为 PNG 不处理 defs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆