Closed aleczratiu closed 4 years ago
Hi,
Do you have problems with image loading/decoding with Node.js? Please try to convert your image format to an ImageData-like object. Note: this is an 8-bit array, not a 16-bit array.
ImageData.data Is a Uint8ClampedArray representing a one-dimensional array containing the data in the RGBA order, with integer values between 0 and 255 (inclusive). ImageData.height Is an unsigned long representing the actual height, in pixels, of the ImageData. ImageData.width Is an unsigned long representing the actual width, in pixels, of the ImageData.
It's mentioned (but probably not emphasized) in the README, that ImageTracer supports only imagedataToSVG()
and imagedataToTracedata()
with Node.js, image loading/decoding is not in the scope of this project.
If you already have a 16-bit ImageData, then you can try to edit imagetracer.js, search and replace 255 with 65535 where it's relevant in and change this cdl
value in line 314 to 4*65535. I can't guarantee that this will work, but you can try. :)
Hi @jankovicsandras, thank you for answer. I already use on NodeJS server to parse some png to svg for test https://png-to-svg.herokuapp.com/ where I test the package. If depth is 16 or 32 I try to convert it on 8 bit but I still have some bugs with some png it multiply the content from image by 3 like in bellow example. Original png
After is parsed:
And one more thing, the final svg output have some missing fill color I think Original png image:
After is parsed some fill are missing:
Original png Files which was tested:
Hi,
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
</head>
<body onload="onload_init()" style="background-color:rgb(64,64,64);color:white;">
<div id="canvascontainer"></div>
<script src="imagetracer_v1.2.5.js"></script>
<script>
function onload_init(){
ImageTracer.imageToTracedata(
'rocket.png',
function(tracedata){
// creating a palette display
var palettedisplaystr = '</br>';
for(var colidx=0; colidx<tracedata.palette.length; colidx++){
var col = tracedata.palette[colidx];
palettedisplaystr += '<span style="color:rgba('+col.r+','+col.g+','+col.b+','+col.a+');" >██' + colidx + '██ </span>'+(col.a==0?(colidx+' transparent'):'')+'</br>';
console.log(JSON.stringify(col));
}
// appending the traced image and the palette display
ImageTracer.appendSVGString( ImageTracer.getsvgstring(tracedata/*,options*/) + palettedisplaystr );
}
);
}// End of onload_init()
</script>
</body></html>
Result:
More info on PNG colors: https://en.wikipedia.org/wiki/Portable_Network_Graphics#Pixel_format
It doesn't work on 16 bit png images. I changes the PNG parser with https://github.com/lukeapage/pngjs to parse on 16 bit but the output on svg it seems to be wrong position for pixels