ImageMagick png to svg Image Size

前端 未结 1 1107
傲寒
傲寒 2020-12-18 20:03

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

convert Slide3.png Slide3_converted.svg

The problem is the resul

相关标签:
1条回答
  • 2020-12-18 20:51

    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
    
    0 讨论(0)
提交回复
热议问题