jankovicsandras / imagetracerjs

Simple raster image tracer and vectorizer written in JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optimise memory when running imagetracerjs

singuyen opened this issue · comments

Hi guys, I'm running imagetracerjs on a cloud function it works well for simple bitmap images. Thanks for the awesome library you wrote. However, it requires more memory for complex ones and needed to allocate a lot of memory for this, more than normal. Just wondering if there's any existing solution for this. Thanks.

var ImageTracer = require('imagetracerjs' );
var PNGReader = require( 'pngjs' ).PNG.sync.read;
var base64Image = 'data:image/png...'

var png = PNGReader(
    Buffer.from(base64Image.replace(/&#x2F/g, '/').slice("data:image/png;base64,".length), "base64")
);

var myImageData = { width:png.width, height:png.height, data:png.data };
var svgString = ImageTracer.imagedataToSVG( myImageData, options );
    
app.json({
    'svg': svgString
})

Hi,

This is a valid, but a bit ambiguous question.

ImageTracer is not optimized for memory usage, and could be improved. The reason for this was partly to keep things simple. For example, some functions might keep unnecessary references to objects, which could be garbage collected. Garbage collection and automatic memory management might also be different between JavaScript engines.

Can you give me more details? Which function uses too much memory (e. g. Firefox -> F12 -> Memory ) ? What is your input image?

Wait, it's not an issue anymore. I can successfully use this with Firebase cloud function. It runs smoothly now after allocating the memory to 8GB. Thanks for getting back.

Great! :)