Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant get right values for image #1218

Closed
okeoke85 opened this issue Mar 22, 2023 · 1 comment
Closed

Cant get right values for image #1218

okeoke85 opened this issue Mar 22, 2023 · 1 comment

Comments

@okeoke85
Copy link

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 ;

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.

@okeoke85
Copy link
Author

I had it solved, resized to small and lost most of data :), image.resize(10, 10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant