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

时间:2022-12-24 08:57:30

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

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

3 个解决方案

#1


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

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

$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:

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

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.)

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

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

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

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.

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

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

只需查看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"/>

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

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

  • ...inkscape to convert SVG to PNG;
  • ... inkscape将SVG转换为PNG;

  • ...autotrace to convert PNM to SVG;
  • ... autotrace将PNM转换为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...

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

#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.

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

#1


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

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

$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:

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

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.)

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

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

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

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.

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

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

只需查看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"/>

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

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

  • ...inkscape to convert SVG to PNG;
  • ... inkscape将SVG转换为PNG;

  • ...autotrace to convert PNM to SVG;
  • ... autotrace将PNM转换为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...

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

#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.

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