使用ImageMagick进行SVG到PNG的转换不能处理defs? [英] SVG to PNG Conversion with ImageMagick doesn't handle defs?

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

问题描述

答案是我标记的答案,但是在评论中。基本上,请看这里:和符号不工作。所以我倾向于将Imagemagick作为罪魁祸首。



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

 < symbol id =arrowx =25> 

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

解决方案

更新:此接缝是ImageMagick中默认SVG渲染器中的一个错误,忽略 x y on 使用标签(并忽略 g 标签上的转换属性)。请尝试使用rsvg后端。



如果更改,它是否有效:

 < use xlink:href =#arrowx =20y =50>< / use> 

收件人:

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


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天全站免登陆