6

I would like to convert images that have been uploaded by the user (in various formats and conditions) to a vector image format such as .eps. I'm primarily working in PHP.

What options exist?

Jon Kirkman
  • 475
  • 4
  • 10
  • possible duplicate of [Coverstion of SVG into PNG/JPEG/BMP and Vice Versa? ](http://stackoverflow.com/questions/4021756/coverstion-of-svg-into-png-jpeg-bmp-and-vice-versa) – Gordon Nov 02 '10 at 08:28

4 Answers4

7

There are a small number of autotracing software projects released under GPU (for example, POTRACE that you could run via system commands. I can't attest to their quality. Tracing almost always requires some element of human supervision to avoid things looking like a mess of broken pottery, but you won't know until you try. Rather than triggering the tracer via PHP, I would use PHP simply to save incoming images to a temporary folder and then, through cronjob (one- or two-per-minute), crank through the holding folder in batches (you could pace it that way and avoid it being used as a way to DoS your site).

I'm thinking of doing something slightly similar (though not graphic related) for an upcoming project, and I'm considering doing all my heavy lifting on a desktop machine, which would fetch all incoming files and process them before FTPing them back to the server. I'm somewhat nervous about having any complex resource-intensive script like this running on a web server.

Andrew
  • 14,204
  • 15
  • 60
  • 104
2

Imagetracer is a free and open source (Public Domain) library and application which can be used on the server side. Disclaimer: I made these.

You can use ImageTracer.jar from

https://github.com/jankovicsandras/imagetracerjava

like this with PHP:

<?php exec("java -jar ImageTracer.jar input.png outfilename output.svg"); ?>

You can also use the JavaScript version with Node.js on the server side, here's the example code:

https://github.com/jankovicsandras/imagetracerjs/tree/master/nodecli

https://github.com/jankovicsandras/imagetracerjs/blob/master/nodetest/nodetest.js

Andras
  • 196
  • 9
2

Definitelly you can do this with the Inkscape

here is the list of formats it supports What formats can Inkscape import/export?

and it can be of course used with the command line or exec() command Can Inkscape be used from the command line?

Justin
  • 84,773
  • 49
  • 224
  • 367
Vladimir
  • 103
  • 1
  • 9
-8

PHP is not an image editor. It is a hypertext preprocessor.

You have to move to serverfault.com, or even better on some image processing resource, and ask there for some command line utility that can be run from PHP using the system() command.

peterh
  • 11,875
  • 18
  • 85
  • 108
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 5
    I understand the PHP is not an image editor. PHP can interface with many useful libs such as GD and ImageMagik without relying on system(). – Jon Kirkman Oct 07 '10 at 21:22
  • @Jon I can't say GD is whatever useful, but in general - yes. It can even control a hydraulic press via com port. It doesn't mean that questions about hydraulic presses are suitable here. – Your Common Sense Oct 07 '10 at 21:26
  • 2
    @Col.Shrapnel unless I'm missing something, PHP is Turing Complete, so you could program anything computable on it, and estimating vectors to represent a raster image is certainly computable. I also don't see how this question is different from the myriad of other questions that have "use xxx library" as a valid response (e.g. "What regex do I use to parse the src of images on this page in .Net?" -> "You should skip regexes and use the HtmlAgilityPack"). – jball Nov 23 '11 at 14:33
  • Oh, sure, @jball you are welcome to write a tracer in PHP, lol :) – Your Common Sense Nov 23 '11 at 14:52
  • A community delete-answer feature will be useful to help clear this type of content from otherwise useful pages. – matty May 02 '23 at 02:51