jankovicsandras / imagetracerjs

Simple raster image tracer and vectorizer written in JavaScript.
The Unlicense
1.27k stars 169 forks source link

Node Script does not converted perfect SVG (looks different compare to original file) #53

Closed arshad111 closed 3 years ago

arshad111 commented 3 years ago

Hi András Jankovics,

I have used nodejs script to convert png to svg.I have converted few images and its converted perfectly.But in one image it does not converted png to svg,its looks differently in svg.Please check below image. command : node nodecli whatsapp.png outfilename whatsapp4.svg

node version:v10.19.0

png file : whatsapp

svg file whatsapp4

jankovicsandras commented 3 years ago

Hi,

The input PNG file is not in RGBA8888 format, but it has an indexed palette. It seems PNG.js (which is not a part of the ImageTracer project) couldn't convert it to an RGBA8888 ImageData object, so the pixel addressing is wrong.

Luckily it's very easy to fix: just convert the input PNG to RGBA8888, for example with GIMP -> Image -> Mode -> RGB .

arshad111 commented 3 years ago

Okay thanks @jankovicsandras.I dnt have any idea bout this.Can you please give me instruction regarding this. Is there any way to check image is RBGA8888 format or not..if not than how to convert to RGBA8888?

jankovicsandras commented 3 years ago

Most image editors should show the color / palette format under image properties and should be able to convert. I suggested GIMP, because it's free and open source.

  1. Download and install GIMP from here
  2. Open your image and on the top menu: Image -> Mode -> RGB
  3. Save and try imagetracer again

There are many alternatives, also command line / automatic solutions, I recommend searching the web for them. See also Comparison of raster graphics editors

arshad111 commented 3 years ago

Thank you @jankovicsandras , i will check and let you know :)

arshad111 commented 3 years ago

Hi @jankovicsandras , Is there any option to reduce(compress) svg file size?

jankovicsandras commented 3 years ago

There are some options which can reduce the svg file size somewhat, at the cost of quality. You can experiment with these, but SVG as a file format is based on the verbose XML standard, so file size is not a priority for SVG and not in the scope of the ImageTracer project.

numberofcolors : small values get smaller files, try 2 .. 4 .. 8 maybe (default is 16) pathomit: big values discard more paths, try 16 .. 32 ... (default is 8) roundcoords: value 0 will result smaller files (default is 1) ltres ; qtres : big values might get smaller files, try 2 .. 4 .. 8 ... (default is 1)