Page 1 of 1

Converting SVG files with ImageMagick

Posted: 2014-04-03T05:52:21-07:00
by lbalbalba
When I use Imagemagick to convert images to the SVG format, my resulting files tend to get very large. This causes issues for me, for example resulting in an application 'hang' or 'freeze', when I try to open them in applications like LibreOffice or MS Visio.

This even happens for example, when I convert a small SVG file from SVG to SVG like this :

$ convert ./foo.svg ./bar.svg

$ dir
foo.svg 14.947 bytes
bar.svg 445.750 bytes

(The resulting/converted file contains hundreds of lines like this: ' <circle cx="0" cy="0" r="1" fill="white"/> ' )

Is this intended behavior, and/or is there a way to workaround this when converting to SVG using ImageMagick ?

Re: Converting SVG files with ImageMagick

Posted: 2014-04-03T07:40:09-07:00
by dlemstra
This is by design. The SVG is converted to a rasterized image after it has been loaded. If you save the result as an svg file each pixel is saved as a 'circle' that is 1x1. You can avoid this behavior if you install the autotrace delegate.

Re: Converting SVG files with ImageMagick

Posted: 2014-04-03T09:33:10-07:00
by lbalbalba
Thanks for the explanation.

And please forgive me my ignorance, but what exactly is this 'autotrace delegate' you mention, and how do I install and use it ? Im pretty new to ImageMagick.


Thanks.

Re: Converting SVG files with ImageMagick

Posted: 2014-04-03T10:02:33-07:00
by fmw42

Re: Converting SVG files with ImageMagick

Posted: 2014-04-03T23:48:01-07:00
by lbalbalba
Thanks.

So I downloaded the autotrace binaries for Windows, but im running into some issues. I have no idea how to use this from imagemagick, but when I run autotrace on it's own from the commandline like this "autotrace.exe sample1.svg > result.svg" I get these messages:

: Color is not known to X server (url(#grad0-13)).
: Color is not known to X server (url(#grad0-14)).
: Color is not known to X server (url(#grad0-20)).
: Color is not known to X server (url(#grad0-21)).
: Color is not known to X server (url(#grad0-29)).
: Color is not known to X server (url(#grad0-30)).
: Color is not known to X server (url(#grad0-34)).
: Color is not known to X server (url(#grad0-45)).
: Color is not known to X server (url(#grad0-50)).
: Color is not known to X server (url(#grad0-51)).
: Color is not known to X server (url(#grad0-52)).
: Color is not known to X server (url(#grad0-53)).
Followed by a pop-up box stating : Autotrace.exe has stopped working

Should I just file a bug report for autotrace ? Or am I running it the wrong way and should I run it from imagemagick (how ?) instead ?


Anyway, here's the small-ish svg file im using.
sample1.svg wrote: <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by Microsoft Visio, SVG Export server.svg Page-1 -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:v="http://schemas.microsoft.com/visio/2003/SVGExtensions/" width="0.867573in" height="1.32332in"
viewBox="0 0 62.4653 95.2789" xml:space="preserve" color-interpolation-filters="sRGB" class="st14">
<v:documentProperties v:langID="1043" v:metric="true" v:viewMarkup="false">
<v:userDefs>
<v:ud v:nameU="msvNoAutoConnect" v:val="VT0(1):26"/>
</v:userDefs>
</v:documentProperties>

<style type="text/css">
<![CDATA[
.st1 {fill:#ff00ff;fill-opacity:0;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:0;stroke-width:0.72}
.st2 {fill:url(#grad0-7)}
.st3 {stroke:#ffffff;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.36}
.st4 {fill:url(#grad11-12)}
.st5 {fill:url(#grad12-19);stroke:#ffffff;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.36}
.st6 {stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-width:1}
.st7 {fill:url(#grad12-28);stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.36}
.st8 {stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.6}
.st9 {fill:#000000;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.36}
.st10 {fill:url(#grad8-44);stroke:#ffffff;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.12}
.st11 {fill:url(#grad10-49);stroke:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.12}
.st12 {fill:#000000;stroke:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.24}
.st13 {stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.36}
.st14 {fill:none;fill-rule:evenodd;font-size:12px;overflow:visible;stroke-linecap:square;stroke-miterlimit:3}
]]>
</style>

<defs id="Patterns_And_Gradients">
<linearGradient id="grad0-7" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(270 0.5 0.5)">
<stop offset="0" stop-color="#ffffff" stop-opacity="1"/>
<stop offset="1" stop-color="#e1d8c1" stop-opacity="1"/>
</linearGradient>
<pattern id="grad11-12" x="0" y="0" width="1" height="1" patternContentUnits="objectBoundingBox">
<path d="M 0 1 L 0 0 L 1 0 z" style="fill:url(#grad0-13)"/>
<path d="M 0 1 L 1 1 L 1 0 z" style="fill:url(#grad0-14)"/>
</pattern>
<linearGradient id="grad0-13" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(180 0.5 0.5)">
<stop offset="0" stop-color="#ffffff" stop-opacity="1"/>
<stop offset="1" stop-color="#c9ba96" stop-opacity="1"/>
</linearGradient>
<linearGradient id="grad0-14" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(90 0.5 0.5)">
<stop offset="0" stop-color="#ffffff" stop-opacity="1"/>
<stop offset="1" stop-color="#c9ba96" stop-opacity="1"/>
</linearGradient>
<pattern id="grad12-19" x="0" y="0" width="1" height="1" patternContentUnits="objectBoundingBox">
<path d="M 0 0 L 0 1 L 1 1 z" style="fill:url(#grad0-20)"/>
<path d="M 0 0 L 1 0 L 1 1 z" style="fill:url(#grad0-21)"/>
</pattern>
<linearGradient id="grad0-20" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(90 0.5 0.5)">
<stop offset="0" stop-color="#ffffff" stop-opacity="1"/>
<stop offset="1" stop-color="#b6a06d" stop-opacity="1"/>
</linearGradient>
<linearGradient id="grad0-21" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(360 0.5 0.5)">
<stop offset="0" stop-color="#ffffff" stop-opacity="1"/>
<stop offset="1" stop-color="#b6a06d" stop-opacity="1"/>
</linearGradient>
<pattern id="grad12-28" x="0" y="0" width="1" height="1" patternContentUnits="objectBoundingBox">
<path d="M 0 0 L 0 1 L 1 1 z" style="fill:url(#grad0-29)"/>
<path d="M 0 0 L 1 0 L 1 1 z" style="fill:url(#grad0-30)"/>
</pattern>
<linearGradient id="grad0-29" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(90 0.5 0.5)">
<stop offset="0" stop-color="#ffffff" stop-opacity="1"/>
<stop offset="1" stop-color="#339966" stop-opacity="1"/>
</linearGradient>
<linearGradient id="grad0-30" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(360 0.5 0.5)">
<stop offset="0" stop-color="#ffffff" stop-opacity="1"/>
<stop offset="1" stop-color="#339966" stop-opacity="1"/>
</linearGradient>
<linearGradient id="grad0-34" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(270 0.5 0.5)">
<stop offset="0" stop-color="#ffffff" stop-opacity="1"/>
<stop offset="1" stop-color="#e7e4cd" stop-opacity="1"/>
</linearGradient>
<pattern id="grad8-44" x="0" y="0" width="1" height="1" patternContentUnits="objectBoundingBox">
<path d="M 0 0 L 1 0 L 1 1 z" style="fill:url(#grad0-34)"/>
<path d="M 0 0 L 0 1 L 1 1 z" style="fill:url(#grad0-45)"/>
</pattern>
<linearGradient id="grad0-45" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(180 0.5 0.5)">
<stop offset="0" stop-color="#ffffff" stop-opacity="1"/>
<stop offset="1" stop-color="#e7e4cd" stop-opacity="1"/>
</linearGradient>
<pattern id="grad10-49" x="0" y="0" width="1" height="1" patternContentUnits="objectBoundingBox">
<path d="M 0.5 0.5 L 0 0 L 0 1 z" style="fill:url(#grad0-50)"/>
<path d="M 0.5 0.5 L 1 0 L 1 1 z" style="fill:url(#grad0-51)"/>
<path d="M 0.5 0.5 L 0 0 L 1 0 z" style="fill:url(#grad0-52)"/>
<path d="M 0.5 0.5 L 0 1 L 1 1 z" style="fill:url(#grad0-53)"/>
</pattern>
<linearGradient id="grad0-50" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(180 0.5 0.5)">
<stop offset="0" stop-color="#000000" stop-opacity="0.4"/>
<stop offset="1" stop-color="#e7e4cd" stop-opacity="0.4"/>
</linearGradient>
<linearGradient id="grad0-51" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(360 0.5 0.5)">
<stop offset="0" stop-color="#000000" stop-opacity="0.4"/>
<stop offset="1" stop-color="#e7e4cd" stop-opacity="0.4"/>
</linearGradient>
<linearGradient id="grad0-52" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(270 0.5 0.5)">
<stop offset="0" stop-color="#000000" stop-opacity="0.4"/>
<stop offset="1" stop-color="#e7e4cd" stop-opacity="0.4"/>
</linearGradient>
<linearGradient id="grad0-53" x1="0" y1="0" x2="1" y2="0" gradientTransform="rotate(90 0.5 0.5)">
<stop offset="0" stop-color="#000000" stop-opacity="0.4"/>
<stop offset="1" stop-color="#e7e4cd" stop-opacity="0.4"/>
</linearGradient>
</defs>
<g v:mID="0" v:index="1" v:groupContext="foregroundPage">
<title>Page-1</title>
<v:pageProperties v:drawingScale="0.0393701" v:pageScale="0.0393701" v:drawingUnits="24" v:shadowOffsetX="9"
v:shadowOffsetY="-9"/>
<g id="group1-1" transform="translate(18.5,-40.4)" v:mID="1" v:groupContext="group">
<v:custProps>
<v:cp v:nameU="Manufacturer" v:lbl="Manufacturer" v:type="0" v:sortKey="Equipment" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="ProductNumber" v:lbl="Product Number" v:type="0" v:sortKey="Equipment" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="PartNumber" v:lbl="Part Number" v:type="0" v:sortKey="Equipment" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="ProductDescription" v:lbl="Product Description" v:type="0" v:sortKey="Equipment" v:invis="false"
v:ask="false" v:langID="1033"/>
<v:cp v:nameU="AssetNumber" v:lbl="Asset Number" v:type="0" v:sortKey="Asset" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="SerialNumber" v:lbl="Serial Number" v:type="0" v:sortKey="Asset" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="Location" v:lbl="Location" v:type="0" v:sortKey="Asset" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="Building" v:lbl="Building" v:type="0" v:sortKey="Asset" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="Room" v:lbl="Room" v:type="0" v:sortKey="Asset" v:invis="false" v:ask="false" v:langID="1033"/>
<v:cp v:nameU="Department" v:lbl="Department" v:type="0" v:invis="false" v:ask="false" v:langID="1033"/>
<v:cp v:nameU="NetworkName" v:lbl="Network Name" v:type="0" v:sortKey="Network" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="IPAddress" v:lbl="IP Address" v:type="0" v:sortKey="Network" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="SubnetMask" v:lbl="Subnet Mask" v:type="0" v:sortKey="Network" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="AdminInterface" v:lbl="Administrative Interface" v:type="0" v:sortKey="Network" v:invis="false"
v:ask="false" v:langID="1033"/>
<v:cp v:nameU="NumberOfPorts" v:lbl="Number of Ports" v:type="0" v:sortKey="Network" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="CommunityString" v:lbl="Community String" v:type="0" v:sortKey="Network" v:invis="false"
v:ask="false" v:langID="1033"/>
<v:cp v:nameU="NetworkDescription" v:lbl="Network Description" v:type="0" v:sortKey="Network" v:invis="false"
v:ask="false" v:langID="1033"/>
<v:cp v:nameU="CPU" v:lbl="CPU" v:type="0" v:sortKey="Workstation" v:invis="false" v:ask="false" v:langID="1033"/>
<v:cp v:nameU="Memory" v:lbl="Memory" v:type="0" v:sortKey="Workstation" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="OperatingSystem" v:lbl="Operating System" v:type="0" v:sortKey="Workstation" v:invis="false"
v:ask="false" v:langID="1033"/>
<v:cp v:nameU="BelongsTo" v:lbl="Belongs To" v:type="0" v:invis="true" v:ask="false" v:langID="1033"/>
<v:cp v:nameU="ShapeClass" v:lbl="ShapeClass" v:type="0" v:invis="true" v:ask="false" v:langID="1033"
v:val="VT4(Equipment)"/>
<v:cp v:nameU="ShapeType" v:lbl="ShapeType" v:type="0" v:invis="true" v:ask="false" v:langID="1033"
v:val="VT4(Server)"/>
<v:cp v:nameU="MACAddress" v:lbl="MAC Address" v:type="0" v:sortKey="Network" v:invis="false" v:ask="false"
v:langID="1033"/>
<v:cp v:nameU="HardDriveSize" v:lbl="Hard Drive Capacity" v:type="0" v:sortKey="Workstation" v:invis="false"
v:ask="false" v:langID="1033"/>
</v:custProps>
<v:userDefs>
<v:ud v:nameU="HasText" v:val="VT0(0):5"/>
<v:ud v:nameU="SolSH" v:val="VT15({BF0433D9-CD73-4EB5-8390-8653BE590246}):41"/>
<v:ud v:nameU="ShapeClass" v:val="VT0(5):26"/>
<v:ud v:nameU="ShapeType" v:val="VT0(24):26"/>
<v:ud v:nameU="visLegendShape" v:val="VT0(2):26"/>
<v:ud v:nameU="visVersion" v:prompt="" v:val="VT0(15):26"/>
</v:userDefs>
<title>Server</title>
<g id="shape2-2" v:mID="2" v:groupContext="shape">
<title>Sheet.2</title>
<path d="M25.47 64.29 L15.67 58.9 L0 67.68 L0.01 90.24 A16.4883 15.8378 -180 0 0 9.67 95.28 L25.47 86.5 L25.47 64.29
ZM4.35 71.19 A17.0163 16.345 -180 0 0 9.67 73.14 A16.8262 16.1624 0 0 1 4.35 71.19 Z" class="st1"/>
</g>
<g id="shape3-4" v:mID="3" v:groupContext="shape" transform="translate(0,-22.1404)">
<title>Sheet.3</title>
<path d="M9.66 95.28 L25.47 86.44 L15.67 81.04 L0 89.82 A17.0163 16.345 -180 0 0 9.67 95.28 L9.66 95.28 Z"
class="st2"/>
<path d="M9.66 95.28 L25.47 86.44 L15.67 81.04 L0 89.82 A17.0163 16.345 -180 0 0 9.67 95.28" class="st3"/>
</g>
<g id="shape4-9" v:mID="4" v:groupContext="shape" transform="translate(0.00578629,-1.7053E-013)">
<title>Sheet.4</title>
<path d="M9.66 73.14 A16.8262 16.1624 0 0 1 -0 67.66 L0 90.24 A16.4883 15.8378 -180 0 0 9.66 95.28 L9.66 73.14 L9.66
73.14 Z" class="st4"/>
<path d="M9.66 73.14 A16.8262 16.1624 0 0 1 -0 67.66 L0 90.24 A16.4883 15.8378 -180 0 0 9.66 95.28 L9.66 73.14"
class="st3"/>
</g>
<g id="shape5-16" v:mID="5" v:groupContext="shape" transform="translate(9.66374,-0.0250235)">
<title>Sheet.5</title>
<path d="M0 73.16 L0 95.28 L15.8 86.52 L15.8 64.32 L0 73.16 Z" class="st5"/>
</g>
<g id="shape6-22" v:mID="6" v:groupContext="shape" transform="translate(0,-0.000801918)">
<title>Sheet.6</title>
<path d="M25.47 64.29 L15.67 58.9 L0 67.68 L0.01 90.24 A16.4883 15.8378 -180 0 0 9.67 95.28 L25.47 86.5 L25.47 64.29"
class="st6"/>
</g>
<g id="shape7-25" v:mID="7" v:groupContext="shape" transform="translate(-28.4846,-5.95844) rotate(-20)">
<title>Sheet.7</title>
<ellipse cx="0.742023" cy="94.2465" rx="0.742023" ry="1.03244" class="st7"/>
</g>
<g id="shape8-31" v:mID="8" v:groupContext="shape" transform="translate(1.56709,-3.1995)">
<title>Sheet.8</title>
<path d="M0 89.13 A19.4098 17.2445 -94.91 0 0 6.53 92.58" class="st8"/>
<path d="M0 90.48 A19.4098 17.2445 -94.91 0 0 6.53 93.93" class="st8"/>
<path d="M0 91.83 A19.4098 17.2445 -94.91 0 0 6.53 95.28" class="st8"/>
</g>
<g id="group9-38" transform="translate(1.30591,-15.6807)" v:mID="9" v:groupContext="group">
<title>Sheet.9</title>
<g id="shape10-39" v:mID="10" v:groupContext="shape" transform="translate(0,-3.62916)">
<title>Sheet.10</title>
<path d="M0.23 91.83 A16.469 15.8192 -180 0 0 6.76 95.28 a0.33464 0.321438 -180 0 0 0 -0.627196 A16.0209 15.3888
0 0 1 0.36 91.3 a0.216797 0.208244 -180 0 0 -0.36194 0.177032 a0.4725 0.453859 -180 0 0 0.231348
0.349812 Z" class="st9"/>
</g>
<g id="shape11-41" v:mID="11" v:groupContext="shape" transform="translate(2.07661,-4.41974)">
<title>Sheet.11</title>
<path d="M2.01 95.25 A2.51697 1.48969 -90.85 0 0 0.05 94.25 a1.61005 0.825651 -180 0 0 1.95887 1.00351 Z"
class="st10"/>
</g>
<g id="shape12-46" v:mID="12" v:groupContext="shape" transform="translate(0.261182,-0.0313598)">
<title>Sheet.12</title>
<path d="M0 90.07 L0 91.83 A17.7156 17.0167 -180 0 0 6.53 95.28 L6.53 93.52 A18.2954 17.5736 0 0 1 0 90.07 Z"
class="st11"/>
</g>
<g id="shape13-54" v:mID="13" v:groupContext="shape" transform="translate(0.261182,-1.00351)">
<title>Sheet.13</title>
<path d="M0 91.83 A16.0346 15.4021 -180 0 0 6.53 95.28 L6.53 94.84 A17.7227 17.0236 0 0 1 0 91.39 L0 91.83 Z"
class="st12"/>
</g>
<g id="shape14-56" v:mID="14" v:groupContext="shape" transform="translate(0.261182,-0.0627196)">
<title>Sheet.14</title>
<path d="M0 90.07 L0 91.83 A17.7156 17.0167 -180 0 0 6.53 95.28" class="st3"/>
</g>
<g id="shape15-59" v:mID="15" v:groupContext="shape" transform="translate(0.261182,4.26326E-014)">
<title>Sheet.15</title>
<path d="M6.53 95.28 L6.53 93.52 A18.2954 17.5736 0 0 1 0 90.07" class="st13"/>
</g>
</g>
</g>
</g>
</svg>

Re: Converting SVG files with ImageMagick

Posted: 2014-04-04T04:26:34-07:00
by snibgo
I'm not familiar with Autotrace, but as far as I know, ImageMagick uses it for converting raster to vector. So its input would be a raster file, not vector. SVG is vector.

What processing are you trying to do with this image? If you want an SVG output from the process, it may be better not to go via raster. But that depends on what you want to do.

Re: Converting SVG files with ImageMagick

Posted: 2014-04-04T05:13:40-07:00
by lbalbalba
The ultimate thing im trying to achieve here is to create svg files in an automated manner (with unix shell scripts, command line tools, etc.) All output must be in SVG so that I can open the resulting files later in MS Visio and/or LibreOffice.

I figured that one way to achieve this could be :
layer existing svg files on top of each other. For example, I might have a (relatively) large svg file that draws a piece of grass or a lawn or something. I then have a (relatively) small svg file that draws a tree. I then draw the tree svg on top of the lawn svg a at a few different places at coordinates x,y. The end result would then be an SVG file of a lawn with some tree's in it. If I understand correctly, ImageMagick allows you to draw files on top of each other like that.

The problem im running into right now, and try to solve by using 'autotrace delegate' , is that the resulting/exported/converted SVG image using ImageMagick is formatted/constructed in such a way that MS Visio and/or LibreOffice have a hard time opening it. (the application appears to hang or freeze).

Re: Converting SVG files with ImageMagick

Posted: 2014-04-04T05:34:22-07:00
by snibgo
ImageMagick is a tool for processing raster images (dots). It is very powerful at this, a really excellent system. It isn't an SVG processor. It is really bad at taking multiple SVG images and overlaying them to make an output SVG.

Other tools, such as Inkscape, are far better at this.

Re: Converting SVG files with ImageMagick

Posted: 2014-04-04T05:41:28-07:00
by lbalbalba
Thanks. ill take a look at Inkscape, then.