Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

php - Conversion of SVG into PNG/JPEG/BMP and Vice Versa?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...