You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
export function colorScan(dataUrl: string): Promise<RGBAStats> {
return new Promise(async (resolve, reject) => {
let avgRGBA: RGBAStats = bRGBAStats();
Jimp.read(dataUrl)
.then((image) => {
image.resize(10, 10).scan(0, 0, image.bitmap.width, image.bitmap.height, function (x, y, idx) {
// x, y is the position of this pixel on the image
// idx is the position start position of this rgba tuple in the bitmap Buffer
// this is the image
let hex: string = Jimp.rgbaToInt(this.bitmap.data[idx + 0], this.bitmap.data[idx + 1], this.bitmap.data[idx + 2], this.bitmap.data[idx + 3]).toString();
if (avgRGBA.distribution[hex]) { avgRGBA.distribution[hex].count++; }
else { avgRGBA.distribution[hex] = { count: 1, density: 0 }; }
if (x == image.bitmap.width - 1 && y == image.bitmap.height - 1) {
//calculate density
avgRGBA.totalPixelCount = (image.bitmap.width - 1) * (image.bitmap.height - 1)
Object.keys(avgRGBA.distribution).map(hex => {
let item = avgRGBA.distribution[hex];
item.density = item.count / avgRGBA.totalPixelCount;
});
return resolve(avgRGBA);
//Scan finished
}
})
})
.catch((err) => {
reject(err);
});
});
}
Best wishes.
The text was updated successfully, but these errors were encountered:
Hi,
Image url : https://firebasestorage.googleapis.com/v0/b/zetform-63ea7.appspot.com/o/organizations%2FNJR6ywOFZTDVVkXSJ4nG%2Fmonitorings%2F2GfT7uPNKbNevCKs4n2G%2Ftestinstances%2FdsjCbKR9WqHBagWotqTf%2Fscreenshots%2FScreen_SCREENSHOT1_2023-03-21_10%3A29%3A07.jpg?alt=media&token=2a64a50b-880a-41a4-a9ce-3b6a2b12a7e5
I'm getting the result as below like there is only 81 pixels in image but it is not right
rGBAStats : {"distribution":{"4294967295":{"count":100,"density":1.2345679012345678}},"totalPixelCount":81}
My function is like that ;
Best wishes.
The text was updated successfully, but these errors were encountered: