rmagick / rmagick

Ruby bindings for ImageMagick
https://rmagick.github.io/
MIT License
696 stars 140 forks source link

SVG Images are not correctly saved #261

Closed KidA001 closed 1 month ago

KidA001 commented 7 years ago

As an example, I'm using the code from this tutorial, except I'm saving the file as duck.svg instead of duck.gif.

When I try to open the SVG file in an any image viewer that supports SVG, I get this error: Line 5: Error: Couldn't find end of Start Tag g. This happens with any SVG file I try and create

Here's the XML of the SVG File:

<?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>

It looks like it's not creating the tags properly.

rmagick gem version 2.16.0 convert --version = Version: ImageMagick 6.9.7-3 Q16 x86_64

Any help appreciated

paulslaby commented 6 years ago

Same problem here. Have you found any solution?

drifty914 commented 6 years ago

I'm also getting the same issue.

ImageMagick -v 6.8.9-9 Q16 x86_64
Rmagick -v 2.16.0
Ruby -v 2.3.1p112
Ubuntu 16.04
asynts commented 3 years ago

Got the same issue:

require 'rvg/rvg'

image = Magick::RVG.new(100, 100)
image.draw.write "image.svg"

Produces

<?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="100" height="100">
<g style="<defs>
<clipPath id="push">
</svg>

That's ImageMagick 7.0.11-13 and rmagick 4.2.2.

phansch commented 2 years ago

Has anyone found a solution for this? The same happens with to_blob.

Watson1978 commented 1 month ago

This is similar with https://github.com/rmagick/rmagick/issues/226

This problem should be reported to ImageMagick. The broken file is saved when SVG is processed and saved with ImageMagick commands.

convert -density 100 -background none Ghostscript_Tiger.svg test.svg

As long as ImageMagick cannot save correctly, RMagick cannot save correctly either