Page 1 of 1

Saving as SVG File

Posted: 2017-01-18T11:33:21-07:00
by kida001
I'm using the rmagick ruby gem. Any file I try to save as a SVG throws an error when I try to open it in a application that can view SVGs

Error: Couldn't find end of Start Tag g

Raw SVG File:

Code: Select all

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="180" height="180">
<g style="<defs>
<clipPath id="70307562988220">
">
<g style="">
  <path d="M0,0 l180.0,0 l0,180.0 l-180.0,0 l0,-180.0z"/>
</g>
</clipPath>
</defs>
clip-path:url(#70307562988220);<g style="rotate(-30.0) fill:yellow;stroke:black;stroke-width:2.0;" transform="matrix(0.72 0 0 0.72 100 150)">
<g style="" transform="matrix(0.72 0 0 0.72 100 150)">
  <ellipse cx="0" cy="0" rx="50" ry="30"/>
</g>
<g style="skewX(-35.0) " transform="matrix(0.72 0 0 0.72 100 150)">
  <rect x="-20" y="-10" width="45" height="20"/>
</g>
</g>
<g style="stroke:black;stroke-width:2.0;" transform="matrix(0.72 0 0 0.72 130 83)">
<g style="fill:yellow;" transform="matrix(0.72 0 0 0.72 130 83)">
  <circle cx="0" cy="0" r="30"/>
</g>
<g style="fill:black;" transform="matrix(0.72 0 0 0.72 130 83)">
  <circle cx="10" cy="-5" r="5"/>
</g>
<g style="fill:orange;" transform="matrix(0.72 0 0 0.72 130 83)">
  <polygon points="30,0 70,5 30,10 62,25 23,20 30,0 "/>
</g>
</g>
<g style="rotate(15.0) " transform="matrix(0.72 0 0 0.72 75 188)">
<g style="" transform="matrix(0.72 0 0 0.72 75 188)">
<g style="fill:orange;stroke:black;stroke-width:2.0;" transform="matrix(0.72 0 0 0.72 75 188)">
  <path d="m0,0 v30 l30,10 l5,-10, l-5,-10 l-30,10z"/>
</g>
</g>
</g>
<g style="rotate(-15.0) " transform="matrix(0.72 0 0 0.72 100 185)">
<g style="" transform="matrix(0.72 0 0 0.72 100 185)">
<g style="fill:orange;stroke:black;stroke-width:2.0;" transform="matrix(0.72 0 0 0.72 100 185)">
  <path d="m0,0 v30 l30,10 l5,-10, l-5,-10 l-30,10z"/>
</g>
</g>
</g>
<g style="" transform="matrix(0.72 0 0 0.72 100 185)">
<g style="fill:black;font-family:helvetica;font-size:20;</svg>
Created the file following this tuturial (https://rmagick.github.io/rvgtut.html), however any file I create and save as an SVG throws this error. Looks like it's messing up the tags on line 5 of the xml.

Any help appreciated

Re: Saving as SVG File

Posted: 2017-01-18T11:46:54-07:00
by kida001
Corresponding GitHub Issue here: https://github.com/rmagick/rmagick/issues/261

Re: Saving as SVG File

Posted: 2017-01-18T12:49:28-07:00
by snibgo
As you say, it has messed up line 5 of the SVG.

Please say what version of IM you are using, and give an example command etc that produces the problem.

Re: Saving as SVG File

Posted: 2017-01-18T12:57:35-07:00
by kida001
Versions:
rmagick gem version 2.16.0
convert --version ImageMagick 6.9.7-3 Q16 x86_64

Code I'm using to execute

Code: Select all

1  require 'rvg/rvg'
 2  include Magick
 3
 4  RVG::dpi = 72
 5
 6  rvg = RVG.new(2.5.in, 2.5.in).viewbox(0,0,250,250) do |canvas|
 7      canvas.background_fill = 'white'
 8
 9      canvas.g.translate(100, 150).rotate(-30) do |body|
10          body.styles(:fill=>'yellow', :stroke=>'black', :stroke_width=>2)
11          body.ellipse(50, 30)
12          body.rect(45, 20, -20, -10).skewX(-35)
13      end
14
15      canvas.g.translate(130, 83) do |head|
16          head.styles(:stroke=>'black', :stroke_width=>2)
17          head.circle(30).styles(:fill=>'yellow')
18          head.circle(5, 10, -5).styles(:fill=>'black')
19          head.polygon(30,0, 70,5, 30,10, 62,25, 23,20).styles(:fill=>'orange')
20      end
21
22      foot = RVG::Group.new do |_foot|
23          _foot.path('m0,0 v30 l30,10 l5,-10, l-5,-10 l-30,10z').
24                styles(:stroke_width=>2, :fill=>'orange', :stroke=>'black')
25      end
26      canvas.use(foot).translate(75, 188).rotate(15)
27      canvas.use(foot).translate(100, 185).rotate(-15)
28
29      canvas.text(125, 30) do |title|
30          title.tspan("duck|").styles(:text_anchor=>'end', :font_size=>20,
31                         :font_family=>'helvetica', :fill=>'black')
32          title.tspan("type").styles(:font_size=>22,
33                 :font_family=>'times', :font_style=>'italic', :fill=>'red')
34      end
35      canvas.rect(249,249).styles(:stroke=>'blue', :fill=>'none')
36  end
37
38  rvg.draw.write('duck.svg')

Re: Saving as SVG File

Posted: 2017-01-20T17:56:10-07:00
by kida001
Anyone?

Re: Saving as SVG File

Posted: 2017-01-25T15:16:54-07:00
by kida001
Great support here! Seems like it just can't properly export SVG and is broken.

Re: Saving as SVG File

Posted: 2017-01-25T17:30:32-07:00
by snibgo
You are using RVG, Ruby Vector Graphics, which is "a facade for Draw that provides a high-level API for scalable vector graphics." It seems to be something layered on top of ImageMagick. As far as I can see, ImageMagick contains no facility for writing vector graphics objects such as ellipses and polygons to SVG files.

In other words, I think this is the wrong place for your question. Try "How to get help" at https://rmagick.github.io/index.html