2

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:

enter image description here

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

convert test.svg test.png

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

enter image description here

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.

Dave Sanders
  • 3,135
  • 4
  • 33
  • 43
  • Seams like a bug :( But a workaround is to use Inkscape instead which seams to render the SVG correctly. Inkscape has support for converting to PNG from command line if that's what you are looking for. – Mattias Wadman May 18 '12 at 20:17
  • Sadly, I have to do it with ImageMagick. In reality, this is going to be used with RMagick (Rails interface to IM) and be done server side at Heroku. And I don't think I have any other option. – Dave Sanders May 18 '12 at 20:19

2 Answers2

2

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>
Mattias Wadman
  • 11,172
  • 2
  • 42
  • 57
  • 1
    Bummer. But i found [this thread about the issue](http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=18816), could you recompile imagemagick to use rsvg? – Mattias Wadman May 18 '12 at 20:54
  • BINGO - that did it. Now to find out if Heroku can support it - so far I don't think it does... – Dave Sanders May 21 '12 at 14:57
  • Let me add - its working via command line, but NOT via RMagick. So, I guess its halfway there, and I suspect some config I need to supply to RMagick. Nothing's easy. :) – Dave Sanders May 21 '12 at 15:20
  • Ah ok :) two imagemagick installations in different paths? let me know if you think my updated answer is wrong. – Mattias Wadman May 21 '12 at 15:30
  • Sigh, yes, apparently I have two versions and RM is using the wrong one. Trying to sort that out. – Dave Sanders May 21 '12 at 16:17
0

Can you give more detail as to why you have to use IM? If it turns out that IM is useless in this case, surely you would have to use something else? I second Inkscape for this.

That said, perhaps you can still use IM if you're willing to do some XML manipulation. I presume the contents of a symbol could be copied to their <use> locations individually; it's a messy workaround if you have lots of uses of the same symbol, but if you want to stick with IM it may be your only way forward. I'm working on the theory that it's the symbol system that is confusing IM - if the path is 'inline' it might be ok.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • I have to use ImageMagick because this is being done on a Ruby on Rails app that is hosted on Heroku. Heroku offers ImageMagick, via the RMagick gem, as the way to do image conversions. Since I don't think I have a way to install Inkscape or use their libraries, I'm stuck with IM. – Dave Sanders May 21 '12 at 14:59
  • And yes, I was prepared to basically stop using "use" commands and defs and make it all explicit. But I was staying away from it if I could figure it out. And adding RSVG did the trick. I only hope Heroku will support it. – Dave Sanders May 21 '12 at 15:00