Simple raster image tracer and vectorizer written in JavaScript.
1.2.3
Node.js Command line interface (Enhancement Issue #13)
FIXED: Pathomit problem thanks to EusthEnoptEron (Issue #14)
options.corsenabled for CORS Image loading thanks to neel-radica (Issue #12)
1.2.2
FIXED: missing hole in path because of incorrect bounding box (Issue #11)
Posterized3 option preset
Changed svgpathstring() arguments to simplify getsvgstring()
1.2.1
FIXED: Gaussian blur preprocessing is now independent of DOM and canvas, thus working directly with Node.js (Issue #9)
1.2.0
This is a major update, changing some internal logic and option default values. The API is compatible, so it should work out of the box.
FIXED: transparent holes are now possible. ( Issue #7 and #8 )
Deterministic output by default: options.colorsampling = 2 ; options.mincolorratio = 0 are deterministic and the defaults now.
Right angle enhancing: options.rightangleenhance ( default : true )
Option presets (see below)
Custom strokewidth with options.strokewidth ( default : 1 )
Line filter with options.linefilter ( default : false )
Simplified getsvgstring(); options.desc = false by default; splitpoint = fitpoint in fitseq(); small bugfixes and optimizations
Version history and README for the old 1.1.2 version is here.
Option presets
Are you confused by the many parameters and their meaning in the options object? Just use a preset like this:
// This uses the 'Posterized2' option preset and appends the SVG to an element with id="svgcontainer"ImageTracer.imageToSVG(
'panda.png', // Input filenamefunction(svgstr){ ImageTracer.appendSVGString( svgstr, 'svgcontainer' ); }, // callback function to append the SVG to the svgcontainer div'Posterized2'// Option preset
);
These strings can be passed instead of the options object: 'Default', 'Posterized1', 'Posterized2', 'Posterized3', 'Curvy', 'Sharp', 'Detailed', 'Smoothed', 'Grayscale', 'Fixedpalette', 'Randomsampling1', 'Randomsampling2', 'Artistic1', 'Artistic2', 'Artistic3', 'Artistic4' .
// Loading smiley.png, tracing and calling alert callback on the SVG string result ImageTracer.imageToSVG( 'smiley.png', alert );
More examples:
// Almost the same with options, and the ImageTracer.appendSVGString callback will append the SVGImageTracer.imageToSVG( 'smiley.png', ImageTracer.appendSVGString, { ltres:0.1, qtres:1, scale:10, strokewidth:5 } );
// This uses the 'Posterized2' option preset and appends the SVG to an element with id="svgcontainer"ImageTracer.imageToSVG(
'panda.png',
function(svgstr){ ImageTracer.appendSVGString( svgstr, 'svgcontainer' ); },
'Posterized2'
);
// The helper function loadImage() loads an image to a canvas, then executing callback:// appending the canvas to a div here.ImageTracer.loadImage(
'panda.png',
function(canvas){ (document.getElementById('canvascontainer')).appendChild(canvas); }
);
// ImageData can be traced to an SVG string synchronously.ImageTracer.loadImage(
'smiley.png',
function(canvas){
// Getting ImageData from canvas with the helper function getImgdata().var imgd = ImageTracer.getImgdata( canvas );
// Synchronous tracing to SVG stringvar svgstr = ImageTracer.imagedataToSVG( imgd, { scale:5 } );
// Appending SVGImageTracer.appendSVGString( svgstr, 'svgcontainer' );
}
);
// This will load an image, trace it when loaded, and execute callback on the tracedata:// stringifying and alerting it here.ImageTracer.imageToTracedata(
'smiley.png',
function(tracedata){ alert( JSON.stringify( tracedata ) ); },
{ ltres:0.1, qtres:1, scale:10 }
);
// imagedataToTracedata() is very similar to the previous functions. This returns tracedata synchronously.ImageTracer.loadImage(
'smiley.png',
function(canvas){
// Getting ImageData from canvas with the helper function getImgdata().var imgd = ImageTracer.getImgdata(canvas);
// Synchronous tracing to tracedatavar tracedata = ImageTracer.imagedataToTracedata( imgd, { ltres:1, qtres:0.01, scale:10 } );
alert( JSON.stringify( tracedata ) );
}
);
outfilename or -outfilename REQUIRED
ltres or -ltres
qtres or -qtres
pathomit or -pathomit
rightangleenhance or -rightangleenhance
colorsampling or -colorsampling
numberofcolors or -numberofcolors
mincolorratio or -mincolorratio
colorquantcycles or -colorquantcycles
blurradius or -blurradius
blurdelta or -blurdelta
strokewidth or -strokewidth
linefilter or -linefilter
scale or -scale
roundcoords or -roundcoords
viewbox or -viewbox
desc or -desc
lcpr or -lcpr
qcpr or -qcpr
corsenabled or -corsenabled
Deterministic output
ImageTracer version >= 1.2.0 is deterministic by default, but randomization can be turned back on.
Straight line control point radius, if this is greater than zero, small circles will be drawn in the SVG. Do not use this for big/complex images.
qcpr
0
Quadratic spline control point radius, if this is greater than zero, small circles and lines will be drawn in the SVG. Do not use this for big/complex images.
layercontainerid
No default value
Edge node layers can be visualized if a container div's id is defined.
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
raster image tracer and vectorizer, bitmap to SVG converter
We found that imagetracerjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.
Last updated on 29 Jan 2018
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Socket is joining forces with CISA and other industry leaders at the RSA Conference to sign the Secure by Design pledge, committing to uphold the highest security standards in our products.
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.