将SVG转换为PNG / JPEG / BMP和反之亦然? [英] Conversion of SVG into PNG/JPEG/BMP and Vice Versa?

查看:149
本文介绍了将SVG转换为PNG / JPEG / BMP和反之亦然?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP中的代码将SVG转换为其他图像格式并且相反?

解决方案

嗯,你可能想要使用 ImageMagick GD 功能。但请注意,您无法将 PNG / JPEG / BMP 转换为 SVG,这是一条单行道。



编辑:精化



将SVG(矢量)图像转换为PNG(位图)图像非常简单。 ImageMagick可以做到这一点,我相当肯定GD应该也能做到。如果没有,还有rsvg的PHP绑定。



另一方面,将PNG(位图)转换为SVG(向量)是一个完整的问题。该问题的核心是位图图像非常简单地包含比矢量图像更少的信息:特别是关于形状,线条和结构的信息被平铺到像素goop并且不可挽回地丢失。在某些情况下,可以重建此信息,但从未实际检索或重新发现。



矢量化仅仅是一种基于位图图像创建新矢量图像的方法,具有计算机试图发现线条和形状。这个问题远非微不足道,在自动化设置中,这个过程肯定不完美,甚至不可靠。



只有Jon Skeet可以将PNG转换为SVG。 / p>

Reedit: 自动跟踪和个人体验



一些回去的时候我确实做了一些跟踪光栅图像的工作,为一些小型网络应用程序的原型构建(在这里找到它, MNSFW,需要FFx / Safari / Opera )。使用potrace创建矢量以重复跟踪阈值化的黑/白图像以隔离元素并随后手动重建图像。这是一个艰苦的过程,但我当时没有工作,没有更好的事情要做。



点是:自动跟踪光栅图像以产生矢量图像是最好的打击,并且可靠地获得好的结果需要


  1. 一个好的源图像

  2. 付出了很多努力


Code in PHP to convert SVG into Other Image Formats and opposite??

解决方案

Well, you'll probably want to use the ImageMagick or GD functions. But be aware that you can't convert from PNG/JPEG/BMP to SVG, that's a one-way street.

Edit: Elaboration

Converting an SVG (vector) image to a PNG (bitmap) image is trivial. ImageMagick can do this for sure, and I'm fairly certain GD should be able to as well. If not, there are also PHP bindings for rsvg.

Converting PNG (bitmap) to SVG (vector), on the other hand, is a whole 'nuther problem. The core of the issue is that a bitmap image quite simply contains less information than a vector image: Information about shapes, lines and structure in particular is flattened to pixel goop and irretrievably lost. In some cases, this information can be reconstructed, but never actually retrieved or rediscovered.

Vectorization is merely a method for creating a new vector image based on a bitmap image, having the computer attempt to discover lines and shapes. This problem is far from trivial, and the process is certainly not perfect, nor even reliable in an automated setting.

Only Jon Skeet can convert a PNG into an SVG.

Reedit: Autotracing and personal experience

Some time back I actually did do some work on tracing a raster image for some prototype-building of a small web-app (find it here, MNSFW, requires FFx/Safari/Opera). Creating the vector was done using potrace to repeatedly tracing a thresholded black/white image to isolate elements and subsequently reconstructing the image by hand. It was a grueling process, but I was out of work at the time and had nothing better to do.

Point is: Automatic tracing of raster images to produce vector images is hit-and-miss at best, and reliably getting good results requires

  1. A good source image
  2. A lot of effort

这篇关于将SVG转换为PNG / JPEG / BMP和反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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