Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux CLI - Raster to Vector (Tracing)

I'm running a website on an Ubuntu server. Part of the functionality of this site is providing colored vectorized images. In the end I'm hoping to have an output similar to Vector Magic. While Vector Magic does a wonderful job, they are extremely expensive for the amount of images I wish to process via their API.

I'm attempting to take a raster image, work some magic, and hopefully end up with a (somewhat) clean SVG image via a CLI. I'm aware getting perfect raster > vector images is not possible but a small quality loss is not an issue. The catch is obtaining a vector with both transparency and color.

I've scoured high and low in attempt to find a solution without reinventing anything but it doesn't look good. Here are a few things I've tried before asking here:

  • Inkscape has the best bitmap tracing feature I've found so far. With clean results and colors, it would be a GREAT solution. The issue lies within the fact that this feature cannot be easily automated or used via CLI and is unusable(?) on my Ubuntu server.

  • I've also attempted to use Potrace, however Potrace only traces into black and white. Unfortunately, color is a requirement. I've heard of pre-processing the image using mkbitmap however the next option covers that.

  • Autotrace is the second best solution as it provides a color SVG right from a JPG or PNG raster (using Potrace along with a pre-processor), but the quality is horrendous.

  • KVEC is neat and all but has similar results as Autotrace.

  • As pretty as it may look, embedding a raster within an SVG using is possible but seems to be intensive and somewhat unsupported, so I'd rather steer away from that.

So, my question -- is it possible to go from raster to vector using a CLI utility? Or am I reinventing what already exists to get a semi-decent result? I appreciate any assistance!

like image 430
user3149678 Avatar asked May 18 '16 17:05

user3149678


2 Answers

I figured I would post my answer for other members, just in case:

I was able to use imagetracerjs to solve my issue. They provide nice client and server sided examples. While the quality isn't perfect (as expected with vectorization), it is open source and has plenty of options to get a fairly decent result.

like image 71
user3149678 Avatar answered Oct 04 '22 23:10

user3149678


Don't forget to check out the Java version, it might be easier to use from CLI:

https://github.com/jankovicsandras/imagetracerjava

Basic usage:

java -jar ImageTracer.jar smiley.png

With options:

java -jar ImageTracer.jar smiley.png outfilename output.svg ltres 1 qtres 1 pathomit 8 colorsampling 1 numberofcolors 16 mincolorratio 0.02 colorquantcycles 3 scale 1 simplifytolerance 0 roundcoords 1 lcpr 0 qcpr 0 desc 1 viewbox 0 blurradius 0 blurdelta 20
like image 35
Andras Avatar answered Oct 04 '22 22:10

Andras