ImageMagick png to svg Image Size [英] ImageMagick png to svg Image Size

查看:254
本文介绍了ImageMagick png to svg Image Size的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

convert Slide3.png Slide3_converted.svg

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

The problem is the resulting file is a whopping 380MB!

我试过这个版本的命令:

I tried this version of the command:

convert -size 2000x1200 Slide3.png Slide3_converted_smaller.svg

但没有骰子。相同大小。

But no dice. Same size.

推荐答案

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

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

这里有一个样本来自此命令创建的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>

基本上ImageMagick为每个像素创建一个1px半径圆,并以正确的颜色绘制它。
从5KB png开始,我的输出是22MB 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.

根据ImageMagick文档(参见这里)发生这种情况是因为 AutoTrace (参见这里)库缺失:

According to ImageMagick documentation (see here) this happens because "AutoTrace" (see here) library is missing:


如果未安装AutoTrace库并将其编译为IM,
则生成的 SVG输出将是大量单个像素
,从而生成二进制结果<强大的>而不是平滑的SVG概述
图像。这些图像通过比较是巨大的,并且通常需要很长的
时间来通过SVG渲染渲染。

"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库,你可以试试这样的东西:

once you have installed AutoTrace library you can try with something like this:

convert autotrace:A.gif  A_traced.png

这篇关于ImageMagick png to svg Image Size的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆