Return to Snippet

Revision: 80647
at March 23, 2020 17:50 by chrisaiv


Updated URL
https://www.chrisjmendez.com/2015/01/22/js-turn-image-into-vector-art-silhouette/

Updated Code
https://www.chrisjmendez.com/2015/01/22/js-turn-image-into-vector-art-silhouette/

Updated Description
https://www.chrisjmendez.com/2015/01/22/js-turn-image-into-vector-art-silhouette/

Revision: 68587
at January 25, 2015 05:49 by chrisaiv


Updated Code
var sys = require('sys')
, exec  = require('child_process').exec
, async = require('async')
, util  = require('util')

//!!!Notice that I am removing the file extension
var images = [
    "file1",
    "file2",
    "file3"
]

async.mapSeries(
    images,
    function(image, callback){
        //Manual 
        //http://potrace.sourceforge.net/potrace.1.html
        var params = {
            input:      "bmp/" + image + ".bmp",
            output:     "-o " + "eps/" + image + ".eps",
            resolution: "--resolution 150",
            opaque:     "--opaque",
            alphamax:   "--alphamax 0.2",
            curve:      "--opttolerance 0.5",
            progress:   "--progress"
        }
        //Simple Example
        //exec("potrace " + composer + ".bmp -o " + image + ".eps " , callback);
        exec( 
            util.format( "potrace " + "%s %s %s %s %s %s %s", 
            params.input, 
            params.output,
            params.resolution,
            params.opaque,
            params.alphamax,
            params.curve,
            params.progress
        )
        , callback)
    },
    function(err, results) {
        if(err) console.error(err.message)
        else console.log(results)
    }
)

Revision: 68586
at January 22, 2015 10:29 by chrisaiv


Updated Code
var sys = require('sys')
, exec  = require('child_process').exec
, async = require('async')
, util  = require('util')

var images = [
    "file1",
    "file2",
    "file3"
]

async.mapSeries(
    composers,
    function(image, callback){
        //Manual 
        //http://potrace.sourceforge.net/potrace.1.html
        var params = {
            input:      "bmp/" + image + ".bmp",
            output:     "-o " + "eps/" + image + ".eps",
            resolution: "--resolution 150",
            opaque:     "--opaque",
            alphamax:   "--alphamax 0.2",
            curve:      "--opttolerance 0.5",
            progress:   "--progress"
        }
        //Simple Example
        //exec("potrace " + composer + ".bmp -o " + image + ".eps " , callback);
        exec( 
            util.format( "potrace " + "%s %s %s %s %s %s %s", 
            params.input, 
            params.output,
            params.resolution,
            params.opaque,
            params.alphamax,
            params.curve,
            params.progress
        )
        , callback)
    },
    function(err, results) {
        if(err) console.error(err.message)
        else console.log(results)
    }
)

Revision: 68585
at January 22, 2015 10:25 by chrisaiv


Initial Code
var sys = require('sys')
, exec  = require('child_process').exec
, async = require('async')
, util  = require('util')

var composers = [
    "file1",
    "file2",
    "file3"
]

//Manual 
//http://potrace.sourceforge.net/potrace.1.html
var params = {
    input:      "bmp/" + composer + ".bmp",
    output:     "-o " + "eps/" + composer + ".eps",
    resolution: "--resolution 150",
    opaque:     "--opaque",
    alphamax:   "--alphamax 0.2",
    curve:      "--opttolerance 0.5",
    progress:   "--progress"
}

async.mapSeries(
    composers,
    function(composer, callback){
        //Simple Example
        //exec("potrace " + composer + ".bmp -o " + composer + ".eps " , callback);
        exec( 
            util.format( "potrace " + "%s %s %s %s %s %s %s", 
            params.input, 
            params.output,
            params.resolution,
            params.opaque,
            params.alphamax,
            params.curve,
            params.progress
        )
        , callback)
    },
    function(err, results) {
        if(err) console.error(err.message)
        else console.log(results)
    }
)

Initial URL
http://brewformulas.org/Potrace

Initial Description
I was recently asked to turn a bitmap image (.bmp) into a vector graphic and I wanted to do it using Javascript. NodeJS did the trick with a little help from Node Package Manager and Brew Package Manager.  The first step was to install potrace then install a few other node packages like Async. 

NOTE! USE BMP, not JPG or PNG. Potrace prefers that format.

Initial Title
NodeJS: Turn image into Vector art silhouette

Initial Tags
javascript, js

Initial Language
JavaScript