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

Cannot load buffer as an image in browser #2

Open
Steffi3rd opened this issue Feb 15, 2019 · 2 comments
Open

Cannot load buffer as an image in browser #2

Steffi3rd opened this issue Feb 15, 2019 · 2 comments

Comments

@Steffi3rd
Copy link

I'm using image generated on the fly, and it doesn't work. Is there a solution ?

const logo = "http://www.edgebase.com/companies/amazon/logo?width=80&height=80"

<ColorExtractor src={logo} getColors={colors => console.log(colors)} onError={error => console.log(error)} />

Cannot load buffer as an image in browser
    at BrowserImage../node_modules/node-vibrant/lib/image/browser.js.BrowserImage.load (browser.js:64)
    at ColorExtractor._this.useDefaultImageClass (react-color-extractor.es.js:74)
    at react-color-extractor.es.js:67

```
@nitin42
Copy link
Owner

nitin42 commented Feb 24, 2019

Hey,

Looking at that error message, it seems like you are passing an image array buffer to the src prop. To render this image and extract colors from it, you might wanna convert this buffer to output base64 image.

The code for this conversion could look something like this -

function(buffer) {
    const bytes = new Uint8Array(buffer);

    const image = document.getElementById('image');
    image.src = 'data:image/png;base64,'+encode(bytes);
};

Let me know if this works 👍

@saikiransathpadi
Copy link

Hey,

Looking at that error message, it seems like you are passing an image array buffer to the src prop. To render this image and extract colors from it, you might wanna convert this buffer to output base64 image.

The code for this conversion could look something like this -

function(buffer) {
    const bytes = new Uint8Array(buffer);

    const image = document.getElementById('image');
    image.src = 'data:image/png;base64,'+encode(bytes);
};

Let me know if this works 👍

what is encode? i tried this but its not working

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

3 participants