ImageMagick将png转换为svg图像大小

19

我已经成功地使用以下命令将PNG转换为SVG:

convert Slide3.png Slide3_converted.svg

问题是生成的文件大小高达380MB!

我尝试了这个命令的版本:

convert -size 2000x1200 Slide3.png Slide3_converted_smaller.svg

但是没有成功。尺寸相同。


1
你忘记写PNG文件大小了。将PNG转换为SVG并不是一项容易的任务,你能使用其他转换器吗?http://en.wikipedia.org/wiki/Raster_to_vector http://en.wikipedia.org/wiki/Comparison_of_raster_to_vector_conversion_software - ViliusL
1个回答

20

SVG是一种矢量图像格式,因此将光栅图像(jpg、png、gif等)转换为svg可能是一项复杂的任务。

我尝试使用以下方式将一个简单的图像进行转换:白色背景,红色圆形和蓝色正方形:

convert input.png output.svg

这是使用该命令创建的SVG文件的示例:
<?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>

基本上,ImageMagick为每个像素创建了一个1像素半径的圆形,并用正确的颜色进行绘制。从一个5KB的png开始,我的输出是一个22MB的svg,这解释了你得到的巨大文件大小。
根据ImageMagick文档(请参见here),这是因为缺少“AutoTrace”(请参见here)库:
"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."
一旦安装了AutoTrace库,您可以尝试类似以下内容:
convert autotrace:A.gif  A_traced.png

有没有选项可以简单地将图像嵌入到SVG中?对我来说,创建圆形似乎相当繁琐。甚至矢量化似乎也不应该是默认选项。 - jozxyqk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接