ibezkrovnyi / image-quantization

Image Quantization Library with alpha support (based on https://github.com/leeoniya/RgbQuant.js, https://github.com/timoxley/neuquant and http://www.ece.mcmaster.ca/~xwu/cq.c)
138 stars 11 forks source link

Using Simple API fails during applyPalette call every time #104

Closed matt-in-brissy closed 1 year ago

matt-in-brissy commented 1 year ago

Hi there,

Trying to use the Simple API (very basic example). It seems to fail during the "applyPalette" call at the same progress time every time. If I choose a different image, it will fail at a different progress time for that image. Here's what I've got:

` // load the image const contents = await fspromises.readFile("images/biking.jpg");

// get image metadata var metadata = await sharp(contents).metadata();

// load the image into a buffer var modifiedData = await sharp(contents).toBuffer();

// create the PointContainer from the buffer var pointContainer = imageq.utils.PointContainer.fromBuffer(modifiedData, metadata.width, metadata.height);

// build the Palette (copied directly from example) const palette = await imageq.buildPalette([pointContainer], { colorDistanceFormula: 'euclidean', // optional paletteQuantization: 'neuquant', // optional colors: 64, // optional onProgress: (progress) => console.log('buildPalette', progress), // optional });

// apply the Palette to the image (Seems to fail during this call every time for some reason). const outPointContainer = await imageq.applyPalette(pointContainer, palette, { colorDistanceFormula: 'euclidean', // optional imageQuantization: 'floyd-steinberg', // optional onProgress: (progress) => console.log('applyPalette', progress), // optional }); `

The console shows the following:

applyPalette 0.7557251908396947 applyPalette 1.5114503816793894 applyPalette 2.267175572519084 applyPalette 3.0229007633587788 applyPalette 3.7786259541984735 applyPalette 4.534351145038168 applyPalette 5.290076335877862 applyPalette 6.0458015267175576 applyPalette 6.801526717557252 there was an error: Cannot read properties of undefined (reading 'r')

... now I am very new to Node.js (which I'm using), so excuse me if this is a simple fix, it's just got me perplexed!

Thanks!

Matt.

Raymond-exe commented 2 months ago

@matt-in-brissy I'm running into the same issue, did you ever figure out a fix?

matt-in-brissy commented 1 month ago

@Raymond-exe to be honest I cannot remember, but I did get things working eventually - just needed to play around a little more.