19

I have successfully converted a PNG to an SVG using the following command:

convert Slide3.png Slide3_converted.svg

The problem is the resulting file is a whopping 380MB!

I tried this version of the command:

convert -size 2000x1200 Slide3.png Slide3_converted_smaller.svg

But no dice. Same size.

Guido Anselmi
  • 3,872
  • 8
  • 35
  • 58
  • 1
    you forgot to write png file size. Png to svg is not easy task, can you use other converters? http://en.wikipedia.org/wiki/Raster_to_vector http://en.wikipedia.org/wiki/Comparison_of_raster_to_vector_conversion_software – ViliusL Sep 11 '13 at 07:52

1 Answers1

20

SVG is a vector image format, so converting a raster image (jpg, png, gif etc.) to svg can be a complex task.

I tried to convert a simple image: white background with a red circle and a blue square using:

convert input.png output.svg

here's a sample from the svg file created by this command:

<?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="800" height="600">
  <circle cx="0" cy="0" r="1" fill="white"/>
  <circle cx="1" cy="0" r="1" fill="white"/>
  ...
  <circle cx="218" cy="151" r="1" fill="rgb(255,247,247)"/>
  <circle cx="219" cy="151" r="1" fill="rgb(255,40,40)"/>
  <circle cx="220" cy="151" r="1" fill="red"/>
  <circle cx="221" cy="151" r="1" fill="rgb(255,127,127)"/>
  <circle cx="222" cy="151" r="1" fill="white"/>
  <circle cx="223" cy="151" r="1" fill="white"/>
  ...
  <circle cx="799" cy="599" r="1" fill="white"/>
</svg>

basically ImageMagick created a 1px radius circle for each pixel, painting it in the correct color. Starting from a 5KB png my output was a 22MB svg, this explains the huge file size you obtained.

According to ImageMagick documentation (see here) this happens because "AutoTrace" (see here) library is missing:

"If the "AutoTrace" library is not installed and compiled into IM, then the SVG output generated will be a huge number of single pixel circles, generating a binary result, rather than a smooth SVG outlined image. Such images are huge by comparision, and often take a very long time to render by by SVG render."

once you have installed AutoTrace library you can try with something like this:

convert autotrace:A.gif  A_traced.png
Andrea
  • 11,801
  • 17
  • 65
  • 72
  • Is there an option to simply [embed the image in the svg](http://stackoverflow.com/q/6249664/1888983)? Creating circles seems quite backwards to me. Even vectorizing seems like it shouldn't be the default option. – jozxyqk Jan 19 '15 at 11:46