如何使用ImageMagick将JPEG图像转换为SVG格式?

时间:2009-07-15 16:55:25

标签: imagemagick

如何使用ImageMagick将JPEG图像转换为SVG格式?

3 个答案:

答案 0 :(得分:40)

您需要先使用potrace并转换为位图。

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

答案 1 :(得分:27)

实际上,通过完整安装最新版本的ImageMagick,它应该像以下一样简单:

convert  some.jpeg  some.svg

当然,ImageMagick不能单独完成所有操作 - 它使用委托(帮助程序)来处理SVG输入或输出。 (其他答案已经指出了这一点。)

要查看所有代表(及其各自的命令)的(部分)列表,请运行

convert  -list delegate

要查看所有委托机密隐藏的配置文件,请参阅

convert  -list delegate | grep delegates.xml

要查看(部分)SVG处理委托列表,请运行

convert  -list delegate | grep -i svg

然而,ImageMagick喜欢将一些外部助手实用程序置于“秘密”模式,并且在使用上述命令时不一定会显示它们的存在。

只需查看delegates.xml文件本身即可。在我的系统上它是:

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"/>

正如您所看到的,在我的系统上,ImageMagick安装会自动使用(其中包括)......

  • ... inkscape将SVG转换为PNG;
  • ... autotrace将PNM转换为SVG;

当然,人们可以争论直接使用autotrace的好处 - 但这需要首先手动将whatever-input格式转换为PNM。因此,对于这个初步步骤,你可能会使用ImageMagick ......

答案 2 :(得分:16)

您实际上需要一些软件或代码来在两者之间对图像进行矢量化,因为jpg是一种栅格格式,而SVG是一种矢量格式。我不认为imagemagick可以为你做到这一点。