How to convert a JPEG image into SVG format using ImageMagick?

蓝咒 提交于 2019-12-31 08:08:51

问题


How to convert a JPEG image into SVG format using ImageMagick?


回答1:


you'll need to use potrace and convert to a bitmap first.

$convert input.jpg output.ppm
$potrace -s output.ppm -o svgout.svg



回答2:


Actually, with a complete installation of a recent version of ImageMagick it should be as easy as:

convert  some.jpeg  some.svg

Of course, ImageMagick cannot do it all by itself -- it uses delegates (helper programs) to handle SVG input or output. (This has been pointed out by other answers already.)

To see a (partial) list of all delegates (and their respective commands), run

convert  -list delegate

To see the config file where all the delegate secrets hide, see

convert  -list delegate | grep delegates.xml

To see a (partial) list of SVG handling delegates, run

convert  -list delegate | grep -i svg

However, ImageMagick likes to put some of its external helper utilities into 'stealth' mode and doesn't necessarily reveal their presence when using above commands.

Just look into the delegates.xml file itself. On my system it's:

grep -i svg /opt/local/etc/ImageMagick/delegates.xml | grep -i --color stealth

  <delegate decode="autotrace" stealth="True" \
            command="&quot;/opt/local/bin/convert&quot; &quot;%i&quot; \
            &quot;pnm:%u&quot;\n\
            &quot;/opt/local/bin/autotrace&quot; \
           -input-format pnm \
           -output-format svg \
           -output-file &quot;%o&quot; &quot;%u&quot;"/>

  <delegate decode="svg:decode" stealth="True" \
            command="&quot;/opt/local/bin/inkscape&quot; &quot;%s&quot; \
            --export-png=&quot;%s&quot; \
            --export-dpi=&quot;%s&quot; \
            --export-background=&quot;%s&quot; \
            --export-background-opacity=&quot;%s&quot; \
            &gt; &quot;%s&quot; 2&gt;&amp;1"/>

As you may see, on my system the ImageMagick installation automatically uses (amongst others)...

  • ...inkscape to convert SVG to PNG;
  • ...autotrace to convert PNM to SVG;

Of course, one could argue the benefits of rather using autotrace directly -- but that would require to manually convert the whatever-input-format to PNM first. So for this preliminary step you'd probably use ImageMagick anyway...




回答3:


You'll actually need some software or code to vectorize your image in between, as jpg is a raster format, while SVG is a vector format. I don't think imagemagick alone can do that for you.



来源:https://stackoverflow.com/questions/1132601/how-to-convert-a-jpeg-image-into-svg-format-using-imagemagick

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!