jankovicsandras / imagetracerjs

Simple raster image tracer and vectorizer written in JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request of demo - React possibly

damiano216 opened this issue · comments

Is there a demo on how to use the package on react or on vanilla js? Something link a codesandbox... Thanks!

Hi,

From README.md :

Getting started

Using in the Browser

Include the script:

<script src="imagetracer_v1.2.6.js"></script>

Then:

// Loading an image, tracing with the 'posterized2' option preset, and appending the SVG to an element with id="svgcontainer"
ImageTracer.imageToSVG(

	'panda.png', /* input filename / URL */
	
	function(svgstr){ ImageTracer.appendSVGString( svgstr, 'svgcontainer' ); }, /* callback function to run on SVG string result */
	
	'posterized2' /* Option preset */
	
);

This is vanilla JS in the browser. I'm not a React expert, but I think this should work.

If you are thinking of using imagetracerjs on the server side (for example Node.js) , that should also work, but you might need to load the image to an ImageData object and use the Synchronous tracing commands. Please look at the nodecli example for details.

I hope this helped. Feel free to reopen the Issue, if you have more questions.