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

Allow passing buffer to getColor in nodejs #201

Closed
m-soli opened this issue Dec 16, 2020 · 1 comment
Closed

Allow passing buffer to getColor in nodejs #201

m-soli opened this issue Dec 16, 2020 · 1 comment

Comments

@m-soli
Copy link

m-soli commented Dec 16, 2020

Currently only possibility is to pass a url to getColor as far as I can tell.

When passing a buffer to getColor - getPixels throws an error of invalid file type because it expects a type param
https://github.com/scijs/get-pixels/blob/master/node-pixels.js#L130

however getColor only takes img and quality attributes - is it possible to call getColor with a third type attribute
https://github.com/lokesh/color-thief/blob/master/src/color-thief-node.js#L59

I imagine something of this sort:

function getColor(img, quality, mimeType) {
    return new Promise((resolve, reject) => {
        getPalette(img, 5, quality, mimeType) // pass this to loadImage and then to getPixels or some other solution
            .then(palette => {
                resolve(palette[0]);
            })
            .catch(err => {
                reject(err);
            })
    });

}
@m-soli
Copy link
Author

m-soli commented Dec 16, 2020

Duplicate - PR already exists to resolve this - #174

@m-soli m-soli closed this as completed Dec 16, 2020
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